最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Setting default date format for datepicker? - Stack Overflow

programmeradmin2浏览0评论

I have a page where I keep track of various dates. So I end up using datepicker through jquery anywhere from 10-200 times. I want to set the default for all cases of datepicker to the 'yy-mm-dd' - but I can't seem to figure out how to set that?

I have a page where I keep track of various dates. So I end up using datepicker through jquery anywhere from 10-200 times. I want to set the default for all cases of datepicker to the 'yy-mm-dd' - but I can't seem to figure out how to set that?

Share Improve this question asked Feb 22, 2012 at 19:01 Sol OrwellSol Orwell 1151 gold badge3 silver badges9 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 26

I end up using datepicker through jquery anywhere from 10-200 times.

I'm assuming you're calling datepicker() separately for each input, probably by id. There's no need for that.

Use a class as a hook on your input:

<input class="my-datepicker">

Then call datepicker on elements with that class with your default configuration:

$('.my-datepicker').datepicker({
    dateFormat: 'yy-mm-dd'
});

When you need a different configuration, use/assign a different class name.

You can also use setDefaults (probably what you're looking for):

$.datepicker.setDefaults({
    dateFormat: 'yy-mm-dd'
});

Go to the file jquery.ui.datepicker.js.

function Datepicker()
{
     dateFormat: 'mm/dd/yy'
}

Change it to the format you prefer. It will change the format for your whole website.

发布评论

评论列表(0)

  1. 暂无评论