jquery datepicker - 两个日期格式相同时发生冲突
我有一个带有两个日期字段的表单。这是一个很大的表格,所以我只展示相关部分。
<input id="dateofassessment" name="dateofassessment" readonly="readonly" class='datebox' />
<input id="LastIncident" name="LastIncident" readonly="readonly" class="datebox" />
(我应该指出,“dateofassessment”是表单中的第一项,“LastIncident”是最后一项)
我像这样附加日期选择器对象。
$(".datebox").datepicker({
dateFormat: 'dd-M-yy',
changeYear: true,
showButtonPanel: false
});
“dateofassessment”输入框工作得很好。日历显示正常,单击日期即可填写“评估日期”字段 - 完美!
然而,“LastIncident”框的效果不太好。单击它会显示日历“确定”。但是,选择日期并不填写表格。事实上,日历在“最后事件”处关闭,并在我选择日期后立即在“评估日期”字段中重新打开。
我无法发布完整的代码,因为内部网站上有大量代码。但希望我已经发布了相关部分。
仅供参考,这些字段是“只读”的事实没有任何区别。
版本... jQuery v1.5.1 日期选择器 1.8.9
I have a form with two date fields. It's quite a big form, so I'll just show the relevant parts.
<input id="dateofassessment" name="dateofassessment" readonly="readonly" class='datebox' />
<input id="LastIncident" name="LastIncident" readonly="readonly" class="datebox" />
( I should point out that "dateofassessment" is the first item in the form, and "LastIncident" is the last item )
I attach the datepicker object like this..
$(".datebox").datepicker({
dateFormat: 'dd-M-yy',
changeYear: true,
showButtonPanel: false
});
The "dateofassessment" input box works perfectly. The calendar is shown OK, and clicking on a date fills in the "dateofassessment"field - Perfect!
However, the "LastIncident" box doesn't work so well. Clicking on it displays the calendar OK. However, selecting a date does not fill in the form. In fact the calendar closes on the "LastIncident", and re-opens on the "dateofassessment" field as soon as I select a date.
I can't post the entire code as there's vast amounts of it, on an intranet site. But hopefully I have posted the relevant parts.
FYI,The fact the fields are "readonly" doesn't make any difference.
Versions...
jQuery v1.5.1
Datepicker 1.8.9
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
嗯,这显然是日期选择器的错误。使用
“尝试”
我知道它会让您重复自己,这很糟糕,但它可以帮助解决问题。或者您可以尝试另一个日期选择器。或者更新这个新版本
Well that's obviousely bug with datepicker. Insted of using
Try
I know it makes you repeat yourself which is bad but it could help to sort out the problem. Or you can try another datepicker. Or update this one the newer version
您的问题位于其他地方,请参阅此小提琴,它按预期工作:http://jsfiddle.net/AfmpL/
Your problem is located elsewhere, see this fiddle which works as expected : http://jsfiddle.net/AfmpL/
您还可以使用 .setDefaults 使所有日期选择器的行为相同(我的母版页中有我的日期选择器,甚至不在 OnDocumentReady 中,因为我希望它在 OnDocumentReady 函数之前运行)。
因此,您几乎不必重复太多内容。
You can also use .setDefaults to make all datepickers behave the same (I have mine in my masterpage, not even in OnDocumentReady, because I want it run before OnDocumentReady functions).
And therefore, you won't have to repeat yourself nearly as much.
尝试使用此 JavaScript:
然后使用以下表单字段:
Try using this JavaScript:
Then use the following form fields: