【问题标题】:jQuery Datepicker setDate not working in IE 6, 7jQuery Datepicker setDate 在 IE 6、7 中不起作用
【发布时间】:2023-04-04 15:53:01
【问题描述】:

我使用 IE 67。 我的项目包含 jQuery.js v.1.9.1 和 jQuery UI v.1.9.2

我有带有 jQ​​uery 日历字段的 html 页面:

...
<input type='text' id='Birthday'>
<!-- for only test purpose-->
<input type='button' style="width: 100px;" value="Get value" id='getValue'>
...

还有 javascipt 文件:

$(document).ready(function () {
     $('#Birthday').datepicker({showOn: "button"});
     $('#Birthday').datepicker("setDate", new Date(1930, 0, 1));
     $('#getValue').click(function(){
          alert($('#Birthday').datepicker("getDate"));
     });
});

然后我编辑输入文本框(没有打开日历对话框)并将日期设置为 01/01/1958 并单击“获取值”按钮。警报框将显示 01/01/1930(日期错误)。 我尝试在"setDate" 之后使用.datepicker("refresh") 命令,但结果相同。

如何修复 jQuery UI setDate 函数以在 IE 6...10 中工作?

【问题讨论】:

  • 你的问题是这里可能没有开发人员仍然使用 IE 6/7 :D 为什么不使用任何现代浏览器?即使在 IE8 中使用兼容性视图,它也可以正常工作。
  • 项目要求是我们必须使用 IE 6,7 及更高版本。并且项目经理拒绝停止支持旧版本的库:-(
  • 我喜欢它,因为项目要求意味着开发人员在 IE6 上花费的时间比实际使用 IE6 的真实用户花费的时间要多。嗯。我的猜测是它抛出了某种 JS 错误,但 IE6/7 没有报告它。遗憾的是 IE6/7 没有像样的开发工具,但是如果您可以使用 IE7 兼容模式在更高版本的 IE 中获得相同的效果,那么您可以使用控制台来观察错误并查看发生了什么。 (如果它在兼容模式下没有发生,那么您需要找到另一种调试 IE6/7 的方法......祝你好运!)

标签: jquery jquery-ui internet-explorer-7 datepicker internet-explorer-6


【解决方案1】:

我通过在 Datepicker 中添加 onSelect 参数解决了这个问题:

$('#Birthday').datepicker({
   showOn: "button",
   onSelect: function()
   {
     // this will fire change on the underlying input
     $(this).change();
   }
});

此代码在 IE 6/7/8/9 中运行良好。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-30
    • 2010-12-29
    • 1970-01-01
    相关资源
    最近更新 更多