简体   繁体   中英

Current date selected by default in twitter bootstrap datepicker

I am trying to have a current date selected by default in twitter bootstrap datepicker. After googling for a while I found the way to do this. Basically I have to do something like this:

$('#date').datepicker('setDate', new Date());
$('#date').datepicker('update')
$('#date').datepicker({
    autoclose: true,
    startDate: '-2m',
    endDate: '+1d'
});

This works nicely, but the code look ugly (why do I need to touch datepicker 3 times). Looking into documentation I have not found a way to do this in one function.

After my last attempt:

$('#date').datepicker({
    autoclose: true,
    startDate: '-2m',
    endDate: '+1d',
    setDate:  new Date()
});

I gave up. So is there a way to write the same thing in one function?

What I understand from your post, is that the first two invocations actually call the setDate and update functions. They are not properties, so you cannot set them as you tried.

The third invocation though sets various attributes in an Object Literal Notation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM