【问题标题】:jquery ui datepicker IE reload or jumps to the top of the pagejquery ui datepicker IE 重新加载或跳转到页面顶部
【发布时间】:2010-02-03 15:45:38
【问题描述】:

我在 IE 7 + 8 中注意到了这个问题

$('#event-start-date').datepicker({dateFormat:'DD MM dd yy',minDate:'-0d'});

当您在 IE 7 或 8 中选择日期时,页面会转到 # 并重新加载根页面

我正在使用 jquery 1.4.0 和 ui 1.7.2

【问题讨论】:

  • 听起来点击处理程序没有返回 false。但如果是这样的话,我希望这会在所有浏览器中发生。
  • 升级到版本 1.4.1 解决了这个问题,因为它在 1.3.2 中很好
  • 似乎在 1.4.2 和 1.8.4 中问题又回来了(如果已修复)。

标签: internet-explorer jquery-ui datepicker


【解决方案1】:

我在使用 IE7 的 jquery 1.4.2 中遇到了同样的问题。这仅在使用模式对话框时发生在我身上。日期选择器很好地显示在页面上,但选择日期会导致您被重定向到 # 片段。

我在这里找到了一个可行的修复方法:http://forum.jquery.com/topic/modal-dialog-with-datepicker

基本上你只需在选择框上撕下href:

.datepicker({ onSelect: function() { $(".ui-datepicker a").removeAttr("href"); } });

或者,如果您在动态加载和重新绑定的内容上使用日期选择器,您可能必须先丢失类:

$("#your_text_box_id").removeClass('hasDatepicker').datepicker({ onSelect: function() { $(".ui-datepicker a").removeAttr("href"); } });

由于 jquery datepickers 和 IE 的许多其他问题,我花了一段时间才找到这个,去看看。

【讨论】:

  • 非常感谢!我希望他们将其添加到 jQuery 的代码中。
  • 这为我节省了一天的时间。谢谢!
  • 但现在例如minDatemaxDate 选项被忽略。
  • 性感的解决方案,我喜欢它,我添加了不丢失光标的样式:$(".ui-datepicker a").removeAttr("href").css('cursor', 'pointer' );
【解决方案2】:

我对 FF 3.6.13、从 jquery CDN 和 jqueryui 1.8.9 交付的 Jquery 1.5.0 和 jqueryui 1.8.9 有同样的问题。

非常奇怪的是,它只发生在某些具有相同版本的 firefox 且缓存已清除的计算机上。

这个修复对我有用。即

$(".datepicker").datepicker({
  dateFormat: "yy-mm-dd",
  changeMonth: true,
  changeYear: true,
  numberOfMonths: 2,
  showButtonPanel: true,
  onSelect: function() {
    $(".ui-datepicker a").removeAttr("href");
  }
});

唯一的问题是它现在忽略了.change 事件。我通过添加 $(this).change():

解决了这个问题
$(".datepicker").datepicker({
  dateFormat: "yy-mm-dd",
  changeMonth: true,
  changeYear: true,
  numberOfMonths: 2,
  showButtonPanel: true,
  onSelect: function() {
    $(".ui-datepicker a").removeAttr("href");
    $(this).change();
  }
});

$(".date_unix").datepicker({
  dateFormat: "@",
  changeMonth: true,
  changeYear: true,
  numberOfMonths: 2,
  showButtonPanel: true,
  onSelect: function() {
    $(".ui-datepicker a").removeAttr("href");
    $(this).change();
  }
});

【讨论】:

  • 有了这个解决方案,minDatemaxDate之类的选项不会被忽略(与其他答案相反)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-15
  • 1970-01-01
  • 1970-01-01
  • 2015-10-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多