简体   繁体   English

IE浏览器不会触发我的jQuery的.click函数。 我能做什么?

[英]IE wont fire my jquery's .click function. what could i do?

okay i have the following code below: 好的,我在下面有以下代码:

SCRIPT: 脚本:

 <script>
 $(document).ready(function() {
      $(".header").click(function () {
   $(this).effect("bounce", { times:2 }, 200);
     $(".links").show("slow");
   });
 });
 </script>

HTML: HTML:

 <body>
   <div class="header">
     <p><img src="images/logo.png" width="438" height="131" alt="Larz Conwell" /></p>
     <p><span class="dash">//</span> Freelance Web Designer &amp; Graphic Artist</p>
   </div> 
   <div class="links">
   </div>
 </body>

and in IE it wont work at all, but it works on all the other browsers. 在IE中根本无法使用,但在所有其他浏览器上都可以使用。 what could be the problem? 可能是什么问题呢?

also i tried another site i have with jquery on it and it works perfectly. 我也尝试过另一个网站,上面有jquery,它的工作原理非常完美。

I think the javascript is getting executed even before the DOM is ready. 我认为javascript甚至在DOM准备就绪之前就已经开始执行。 Try using $.live(); 尝试使用$ .live();

$('.header').live('click', function(){});

This would execute the event even if the class is created later in the DOM. 即使该类稍后在DOM中创建,这也将执行事件。

Are you absolutely certain you have jQuery referenced properly? 您绝对确定您已正确引用jQuery吗? That is often the cause of an object expected error on $(document).ready() . 这通常是$(document).ready()object expected错误的原因。 Using the code you've provided I am able to get IE 8 to fire the click event fine. 使用您提供的代码,我可以使IE 8很好地触发click事件。 You can reference jQuery with the following: 您可以使用以下内容引用jQuery:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js" type="text/javascript" language="javascript"></script>

have you tried 你有没有尝试过

jQuery(document).ready(function() {

maybe you have noConflist in another script 也许您在另一个脚本中没有noConflist

<script>
$(document).ready(function() {
$('.header').click(function() {
$('.menu').show('slow', function() { 
      });
    });
   });
</script>

this is the code is used to fix it. 这是用于修复它的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM