English 中文(简体)
页: 1 职能间的争 to——履行零、一、二、三......倍
原标题:jQuery toggle between functions - performed zero, one, two, three ... times

I m 试验利用j Query角在两个职能之间移动。 迄今取得的成果是零散的。 下面是整个审判规则。

<html>
<head>
  <script type="text/javascript" src="../js/jquery.js"></script>
  <script>
  $(document).ready(function(){
     $( #id ).on( click ,function(event){
         $(this).toggle(
             function(){console.log( Hide );},
             function(){console.log( Show );}
         );
     });
  });
  </script> 
</head>

<body>
  <div id="id">Hello</div>
</body>
</html>

So, when I click "Hello" for the first time, nothing appears in the log.

[Nothing]

在第二点点,我得到:

Hide

第三,它补充说:

Show
Hide

第四,它补充说:

Hide
Show
Hide

第五,它补充说:

Show
Hide
Show
Hide

我相信你能够看到以下模式: 为什么这样做? 我对<代码>.stop(true)进行了试验,但没有结果。

感谢。

最佳回答

<代码>toggle(>在点击时执行,因此不需要<代码>click<>/code>。

$( #id ).toggle(
         function(){console.log( Hide );},
         function(){console.log( Show );}
     );

Your current code attaches toggle() to trigger on the click event the first time it is clicked, that is why you don t get anything the first time you click the element.

问题回答

暂无回答




相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签