0

我在某些部分标题上绑定了 .click 事件,因此当用户单击其中一个标题时,该部分会出现/消失。

到目前为止一切顺利,但由于某种原因,当我离线时,它不再起作用了。

我不明白这种行为,有人可以启发我吗?

这是代码:

<script src="jquery-1.4.2.min.js" type="text/javascript" charset="utf-8"></script>

    <script>
    $(function(){

    $("#contactInfoHeader").click(function(){
        if($("#contactInformation").is(":visible")){        
            $("#contactInformation").fadeOut();
        }else{  
            $("#contactInformation").fadeIn();
        }   
        resizeWidget();
    });

    });
    </script>

    <h3 id="contactInfoHeader">Contact Information</h3>
    <div id="contactInformation">Telephone:XXXXXX</div>
4

3 回答 3

2

in jQuery 1.4.x you should use this format for attaching handlers to the ready event.

$(document).ready(function(){
  //add your stuff here
});

or your can keep the $(handler); syntax, but you'll need the closing paren.

<script>
$(function(){

  $("#contactInfoHeader").click(function(){
      if($("#contactInformation").is(":visible")){        
          $("#contactInformation").fadeOut();
      }else{  
          $("#contactInformation").fadeIn();
      }   
      resizeWidget();
  });

});//ADDED ")" here!
</script>
于 2010-07-05T16:47:29.997 回答
2

亲爱的,您使用的是简单的 jQuery,它使用它的在线文件。因此,当您在线时它可以正常工作,但离线时按钮将停止工作。而已。就是这么简单。

于 2012-07-17T09:37:07.643 回答
1

您有一些代码不一致,或者您误认为它有效。

这也应该在 document.ready 中:

$(function() {
/* your code */
});

否则它不会将点击事件附加到任何东西,因为该元素在运行时不存在。

于 2010-07-05T16:35:05.843 回答