且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

javascript脚本无法正常工作并崩溃IE

更新时间:2023-12-05 18:24:28

以下是您的追求:

$(function () {
  var ajaxTimeout;
  function autorun() {
    if ($("#contactForm").is(":visible")){
      if(ajaxTimeout) {
        clearInterval(ajaxTimeout);
        ajaxTimeout = false;
      }
    }
    else if(!ajaxTimeout) {
      ajaxTimeout = setInterval(refreshAjax, 15000);
    }
  }
  setInterval(autorun, 2000);
});

IE完全不像这样使用的命名函数,它覆盖了之前定义的函数。 这是一个长期存在的错误不是修复到IE9 。问题的核心是 $(函数autorun(){正在接管 autorun 这个名字,这只是排队越来越多的自己。

IE doesn't at all like named functions used like this, and it's overriding the previously defined one. This is a long-standing bug not fixed until IE9. The core of the problem is that $(function autorun() { is taking over the autorun name, which is just queuing more and more runs of itself.

此外,***将函数引用传递给 setInterval() 直接,而不是字符串。

Also, it's better to pass function references to setInterval() directly, not strings.