Datepicker does not start with the <input> value

*爱你&永不变心* 提交于 2019-12-11 06:58:24

问题


i have this markup

 <input tabindex="5"  type="text" class="bgFecha date-pick" id="date2" value="12/03/2011" name="date2"/>

Please note the value of the input

but onclick the datepikcer starts with a 2 years later date:

This is the call:

$(function(){
    $('.date-pick').attr('readonly','true');
    $('.date-pick').datePicker({clickInput:true})
});

What is wrong? i need the datepicker to use the value="" date to start.

thanks


回答1:


The default format for jquery datepicker it's mm/dd/yy. You need to use 12/03/11.

Or you can change the date format:

$(function(){
    $('.date-pick').attr('readonly','true');
    $('.date-pick').datePicker({ 
        clickInput:true, 
        altFormat: 'mm/dd/yyyy' // change the date format
    });
});



回答2:


You can try set up date before you init the calendar like this

var today = new Date();
$('.date-pick').each(function(){
  $(this).val(today.toString("mm/dd/yy"));
});


来源:https://stackoverflow.com/questions/7997484/datepicker-does-not-start-with-the-input-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!