javascript Internet Explorer 7 + alert() 不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7765485/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 01:14:23  来源:igfitidea点击:

Internet Explorer 7 + alert() doesn't work

javascriptinternet-explorer-7

提问by donpedroper

Can some of you please tell me why a simple alert()isn't working using jQuery 1.4 in Internet Explorer 7, when it's working in all other browsers? It's been driving me crazy now for the last half an hour..!

你们中的一些人能否告诉我为什么一个简单alert()的不能在 Internet Explorer 7 中使用 jQuery 1.4,而它可以在所有其他浏览器中运行?在过去的半个小时里,它让我发疯了..!

$(document).ready(function(){
    alert("wtf?");
})

This simple example doesn't show an alert in IE7. See for yourself at http://jsfiddle.net/8HQdp/.

这个简单的例子在 IE7 中没有显示警报。在http://jsfiddle.net/8HQdp/ 上亲自查看。

回答by Christian

  1. Ensure your console doesn't show any errors and correct them if there are any.
  2. Be sure you didn't disable browser prompts on IE
  3. Try using window.alert()- it's possible (though improbable) that another alert()is conflicting with window's.
  4. If you have console support, try console.log(alert);and see what it says. It should be something like:

    function alert() {
        [native code]
    }
    
  1. 确保您的控制台没有显示任何错误,如果有,请更正它们。
  2. 确保您没有在 IE 上禁用浏览器提示
  3. 尝试使用window.alert()- 有可能(虽然不太可能)另一个alert()window's冲突。
  4. 如果您有控制台支持,请尝试console.log(alert);查看它的内容。它应该是这样的:

    function alert() {
        [native code]
    }
    

回答by Moe Sweet

I'm using IE8 but with IE7 mode, the alert on http://jsfiddle.net/8HQdp/still triggers. Try changing $ to jQuery and host your own jquery.js.

我正在使用 IE8 但在 IE7 模式下,http://jsfiddle.net/8HQdp/上的警报仍然触发。尝试将 $ 更改为 jQuery 并托管您自己的 jquery.js。

And also try console.log('wtf') before alert so u know whether it's alert or document.ready is broken.

并且在警报之前尝试 console.log('wtf') 这样你就知道它是警报还是 document.ready 坏了。

回答by simonlchilds

It works in IE 7 mode in IE 8 form me. Takes a while but it does trigger.

它在 IE 8 形式的 IE 7 模式下工作。需要一段时间,但它确实触发。

I noticed that there is a semi colon missing from the ready function. should be...

我注意到就绪函数中缺少一个分号。应该...

$(document).ready(function(){

}); //missing semicolon here

Also, try using the shortcut for the DOM ready function...

另外,尝试使用 DOM 就绪函数的快捷方式...

$(function(){
   // code here
});

回答by Ernestas Stankevi?ius

Try using windownot document.

尝试使用windownot document