javascript jQuery 单击事件不工作 IE7 和 IE8

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5821501/
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-25 18:29:07  来源:igfitidea点击:

jQuery click event not working IE7 and IE8

javascriptjqueryinternet-explorereventsclick

提问by elclanrs

The following code in IE7 or IE8 doesn't work. Is this a bug? It works fine in IE6 (Incredible!)

以下代码在 IE7 或 IE8 中不起作用。这是一个错误吗?它在 IE6 中运行良好(难以置信!)

http://jsfiddle.net/zgSmT/

http://jsfiddle.net/zgSmT/

回答by Herman Schaaf

Try using the liveevent, or binding the event after documentload:

尝试使用live事件,或在document加载后绑定事件:

$('#clickme').live('click', function(){
    alert('hey');
});

Also, you're still loading scripts.js, which doesn't exist, in your fiddle example - that might also cause a problem.

此外,scripts.js在您的小提琴示例中,您仍在加载不存在的 ,这也可能会导致问题。

回答by bnieland

You might try

你可以试试

$().ready(function ()
{
    $('#clickme').live('click', function(){
        alert('hey');
    });
}

To ensure everything is loaded.

以确保一切都已加载。