我最近在 IE 中使用 jQuery UI datepicker 脚本时遇到了一个问题:
加载一个带有日期选择器的页面,显示年份和月份下拉列表。
选择一个日期(第一次可以正常工作)。
再次打开日期选择器,但这一次,当您单击其中一个年/月下拉列表时,它会短暂显示然后消失,需要第二次单击才能正确显示。
我有一个小测试页面(见下文),并使用 jQuery 1.4.4 和 jQuery UI 1.8.10(我的生产配置)以及 jQuery 1.5.2 和 jQuery UI 1.8.12 对此进行了测试,并且能够重现它在这两种情况下(使用 IE9 和 IE6)。
<head>
<script type="text/javascript">
$(document).ready(function () {
$("#testDate").datepicker({changeYear:true,
changeMonth:true,
constrainInput:true,
buttonText:'Choose',
showOn:'both',
showButtonPanel:false,
buttonImageOnly:true});
});
</script>
</head>
<body>
<h2>Test</h2>
<input type="text" id="testDate" />
</body>
我一直在尝试通过缩小的脚本进行调试,我必须查看发生这种情况的位置,但我不知道是什么原因导致的。
最佳答案
如果你查看未缩小的源代码 here (1.8.12) 有问题的函数是这样的:
/* Restore input focus after not changing month/year. */
_clickMonthYear: function(id) {
var target = $(id);
var inst = this._getInst(target[0]);
if (inst.input && inst._selectingMonthYear) {
setTimeout(function() {
inst.input.focus();
}, 0);
}
inst._selectingMonthYear = !inst._selectingMonthYear;
},
删除 setTimeout()
调用可以解决 IE6 中的聚焦问题。但不确定副作用可能是什么。我使用本地修改的 jquery-ui 选择了一些日期,它似乎在 Chrome12 和 IE6 中仍然可以正常工作。 可能是 jquery-ui 团队的一个?
编辑找到 bug report - 看起来预定是 1.8.3
关于jQuery UI 日期选择器 - 使用年/月下拉菜单时的 IE 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5816511/