English 中文(简体)
如果我在约束上加上回调, 它会触发它被约束的时候还是每次被调用的时候?
原标题:If I add a callback to a bind does it trigger when its bound or everytime it is called?

我有以下脚本:

$( #target ).bind( click , 
                        function () {
                            $( #target ).css({  display :  none  });
                            $( #targetFake ).css({  display :  inline-block  });
                        },
                        function () {
                            alert( bind callback ); 
                        });

约束回召警示似乎每次点击 # 目标元素时都会触发, 而不是当该元素受约束时只点击一次。 我可以再回召一次, 以确认该绑定发生一次吗?

最佳回答

s 它应该如何运作: 每点击一个事件就触发一个触发器。 绑定在每次 < code> > bind 调用时就发生一次; 如果您不小心用同一个处理器多次调用 < code> bind / code, 您将会看到处理器通过只点击一个 < code > 点击 触发多次 。

然而: 在您的 < a href=> 中, 有两个函数是做什么的? “ http://api.jquery.com/bind/" rel=" nofollow" \\\ code> bind 呼叫? 没有超载可以接受两个函数 。

你可能还想寻找其他的替代方案,例如:

  • Calling a function only once on the spot -- just call it directly, you don t need jQuery for that.
  • Binding a handler that only gets triggered the first time the event happens -- use one for this purpose.
  • Binding a handler normally and calling it once on the spot; you can do this with $(...).bind( click , ...).trigger( click ).
问题回答

暂无回答




相关问题
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: &...

热门标签