jQuery Date Picker Doesn't Show Original Text Value

谁说胖子不能爱 提交于 2019-12-05 06:05:26

I'm not sure why, but this line is clearing the value:

$("#DatePicker").datepicker("option","dateFormat","dd MM yy");

Try adding the option like this if possible, worked for me in Firefox and Chrome:

$("#DatePicker").datepicker({
    changeMonth: true,
    changeYear: true,
    dateFormat: "dd MM yy"
});

Try using another browser like firefox to check if its a browser compatibility issue, not sure about php but on asp.net their is an option to set the textbox text visibility to true

You should use setDate instead of setting input value directly.

$("#birthday").datepicker()
.datepicker("option", "dateFormat", 'dd.mm.yy')
.datepicker('setDate', '<?= $humanoid->getBirthday()->format('d.m.Y') ?>');

Based on Nik's answer this is how I got it to work in "all javascript"

$(".popup-date").each(function(){
    var ele = $(this);
    var v = ele.val();
    ele.datepicker().datepicker("option", "dateFormat", "dd-M-yy").datepicker("setDate", v);
    });

The accepted answer only solves half the problem. The value displays, but the format of the date after being picked by the date picker is then wrong.

My example uses a different date format (eg. 01-Sep-2014) as I just copied the code I finally got to work. I also had to break it down into getting the element and the value as it was sporadic at best when in-lined.

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