English 中文(简体)
页: 1 5. 活活活活活活活活活活
原标题:jQuery unbind/die live event

I have a simple app to add quotes and the possibility to like the quote (not FB like). I have a simple div as a button with following children: a span with the total likes and a paragraph for some text. I need to work with .live() because some of the content is loaded in with AJAX. I need to unbind/die the event because once you clicked the div can t be clicked anymore. But because with .live() you can t use $(this) I tried working with event.target but this has some problems.

我的超文本:

<div class="btnlike">
<span>0</span>
<p>Click to vote</p>
</div>

我的贾瓦特(远与这一事件有关)。

$(".btnlike").live( click ,function(event){     

    var $target;
    if( $(event.target).is("div") ) {
        $target = $(event.target);
    } else {
        $target = $(event.target).parent();
    }

    $target.unbind(event);      

});

但是,我想使用(die)()但因为(这笔)工作没有其他解决办法?

最佳回答

一种解决办法是,如果在生活功能中就这一要素执行,就进行公正的检查。

$(".btnlike").live( click ,function(event){     
    if ($(this).data( clicked )) {
      // already ran it
      return; 
    }
    // mark it as being run
    $(this).data( clicked , true);
});
问题回答

暂无回答




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

热门标签