开发者

Jquery datepicker can't display the value....?

I have a textfield called:"deadline", which is have the value,like this:

    <input type="input" maxlength=10  value="2011-09-14" id="deadline" name="deadline" class="date_picker"></input>

But when I ran this js, it is gone, I can't see the value:

    $('.date_picker').datepicker();  
    $('.date_picker').datepicker('option', 'dateFormat', 'yy-mm-dd', 'showOn', '');  

Why the date_picker disappear my value?开发者_开发技巧 If I want it back,how can I do so? Thanks.


I was also trying to get it worked, and found a solution using jquery nothing else was working. I did it as

    
    $(document).ready(function(){
       $(".datepicker").val('2011-09-14');
    });
    
    


The Date Picker will typically clear your HTML given default value depending on your formatting options. It does, however, have an option for setting the Default Date:

http://jqueryui.com/demos/datepicker/#option-defaultDate

Important Note: Make sure you Default Value matches the format of your dateFormat

So, add to your options the dateFormat with either a string of your value or a JavaScript date object. More information:

Set the date to highlight on first opening if the field is blank. Specify either an actual date via a Date object or as a string in the current dateFormat, or a number of days from today (e.g. +7) or a string of values and periods ('y' for years, 'm' for months, 'w' for weeks, 'd' for days, e.g. '+1m +7d'), or null for today.

Finally, if you continue to have problems, your options string might be malformed. I haven't seen an options string implemented like that, but that doesn't mean it doesn't work. If you still have issues, try implementing your options in a similar format to this:

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


ShaneC was almost correct. The date format should be yy-mm-dd, as one y actually represents two digits in year. See the date format list here: http://docs.jquery.com/UI/Datepicker/formatDate.

See the example: http://jsfiddle.net/william/RtYLB/.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜