自从将 OnSelect 添加到我的 Datepicker 后,该控件不再触发 TextChanged 事件。我的代码如下:
$(function() {
$("#<%=txtStartDate.ClientID %>").datepicker({
minDate: 0,
dateFormat: 'dd-M-yy',
onSelect: function(dateText, inst) {
var theDate = new Date(Date.parse($(this).datepicker('getDate')));
$("#<%=txtEndDate.ClientID %>").datepicker('option', 'minDate', theDate);
}
});
$("#<%=txtEndDate.ClientID %>").datepicker({
dateFormat: 'dd-M-yy'
});
});
<%-- etc ---- %>
<asp:TextBox ID="txtStartDate" runat="server" AutoPostBack="true" OnTextChanged="txtStartDate_TextChanged"></asp:TextBox>
我的其他日期选择器 (txtEndDate) TextChanged 事件确实触发,因此只能将其归因于为 txtStartDate 控件定义的 OnSelect。
非常感谢对此的任何帮助。干杯!
在对 jQuery UI Datepicker 源进行简短检查后,解决方案是自己触发更改事件
...
onSelect: function(dateText, inst) {
var theDate = new Date(Date.parse($(this).datepicker('getDate')));
$("#<%=txtEndDate.ClientID %>").datepicker('option', 'minDate', theDate);
if (inst.input)
inst.input.trigger('change');
}
...
原因是 jQuery UI Datepicker 源代码中的以下几行
if (onSelect)
// trigger custom callback
onSelect.apply((inst.input ? inst.input[0] : null), [dateStr, inst]);
else if (inst.input)
// fire the change event
inst.input.trigger('change');
正如你所看到的,jQuery UI Datepicker 触发了change
如果日期选择器实例是一个默认事件input
字段,但如果您指定了自定义,则不会触发它onSelect
处理程序(就像你所做的那样)。
您可能会说,实际上这是正确的行为,因为它保证了最大的可配置性。您可以决定是否想要change
事件是否以这种方式发生。
但我同意这种行为也许应该被记录下来。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)