我知道如果用鼠标选择日期,jQuery UI 日期选择器会失去焦点。我希望能够将焦点集中在该输入字段上。所以我做了这样的事情
$("#patientDob").live("click", function() {
$("#patientDob").datepicker({
onSelect: function() {
this.focus();
// selecting a date moves the page, so remove the href attribute
$(".ui-datepicker a").removeAttr("href");
},
changeMonth: true,
changeYear: true,
duration: 'fast',
showOn: 'focus'
}).focus();
});
这确实将焦点放在输入字段上,但在 IE 中,它会继续再次加载日历。在 Firefox 或 Chrome 中它不会这样做。
如何才能将焦点放在输入字段上,而无需在 IE 中一次又一次加载日历?
另外,如果我将输入字段设置为只读,并且在 IE 中选择日期后,该字段将失去焦点,如果我尝试按退格键,它会将我带到之前访问过的页面。
我的解决方案使用 beforeShow 事件取消 IE 的显示(因为在 Chrome 和 Firefox 中,它似乎可以正常工作,无需破解)。 onSelect 和 onClose 在将焦点返回到输入框之前设置一个标志。请参阅我的完整文章还发送模糊和更改事件 http://www.objectpartners.com/2012/06/18/jquery-ui-datepicker-ie-focus-fix/如果你需要那些。
$("input.dateInput").datepicker({
/* fix buggy IE focus functionality */
fixFocusIE: false,
onSelect: function(dateText, inst) {
this.fixFocusIE = true;
$(this).focus();
},
onClose: function(dateText, inst) {
this.fixFocusIE = true;
this.focus();
},
beforeShow: function(input, inst) {
var result = $.browser.msie ? !this.fixFocusIE : true;
this.fixFocusIE = false;
return result;
}
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)