jQuery日期选择器不显示原始文本值 [英] jQuery Date Picker Doesn't Show Original Text Value
问题描述
我正在使用jQuery的Date Picker作为表单的一个字段-出生日期.
I'm using jQuery's Date Picker for one of my form's field - Date of Birth.
该字段是使用PHP生成的,并且将填充用户的原始出生日期.单击该字段会显示该小部件,效果很好.
The field is generated using PHP and will be populated with the user's original date of birth. Clicking the field brings up the widget, which it does perfectly fine.
但是,即使文本框出现在浏览器的源代码中,该文本框也不显示原始值.我正在使用Google Chrome.
However, the textbox doesn't show the original value, even though it appears in the browser's source code. I'm using Google Chrome.
以下是jQuery代码:
The following is the jQuery code:
$(function()
{
$("#DatePicker").attr("readonly","readonly");
$("#DatePicker").datepicker({
changeMonth: true,
changeYear: true,
yearRange: "1950:+10"
});
$("#DatePicker").datepicker("option","dateFormat","dd MM yy");
});
这是PHP代码:
echo "<INPUT TYPE=\"TEXT\" NAME=\"$FieldName\" VALUE=\"$OriginalData\" ID=\"DatePicker\" CLASS=\"FullLength\">";
以下是HTML代码(从源代码复制):
And the following is the HTML code (copied from the source code):
<INPUT TYPE="TEXT" NAME="DateOfBirth" VALUE="18 August 2012" ID="DatePicker" CLASS="FullLength">
请告诉我怎么了.谢谢.
Please tell me what's wrong. Thank you.
推荐答案
我不确定为什么,但是此行正在清除值:
I'm not sure why, but this line is clearing the value:
$("#DatePicker").datepicker("option","dateFormat","dd MM yy");
如果可能,尝试添加这样的选项,在Firefox和Chrome中为我工作:
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"
});
这篇关于jQuery日期选择器不显示原始文本值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!