开发者

jQuery UI datepicker 'setDate' method not working

开发者 https://www.devze.com 2023-04-01 16:59 出处:网络
I\'m having some issues with datepicker in jQuery. I\'m trying to put the today date in a field which is a datepicker.

I'm having some issues with datepicker in jQuery.

I'm trying to put the today date in a field which is a datepicker.

I've tried with:

$('#fecha_alta').datepicker('setDate', new Date());
console.log($('#fecha_alta').datepicker(开发者_如何学Python'getDate'));

And

$('#fecha_alta').datepicker('setDate', '+0');
console.log($('#fecha_alta').datepicker('getDate'));

But always log null and also the input shows empty.

What's wrong?


The following code works:

$(document).ready(function() {
  $('#datepicker').datepicker('setDate', new Date());
});

(tested on the jQueryUI datepicker demo page)


If you need to set the date to the current one by default, then you may want to set it at start, when creating the widget:

$('#datepicker').datepick({
  defaultDate: new Date()
});


you can set date like this as well

$('.date-pick').datePicker().val(new Date()).trigger('change')
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号