Home  >  Article  >  Web Front-end  >  Detailed explanation of jQuery live bound events and unbinding examples

Detailed explanation of jQuery live bound events and unbinding examples

黄舟
黄舟Original
2017-06-26 09:22:491972browse

This article will introduce to you the two methods of event and unbinding of live binding in jQuery. I hope this article It will be helpful to all classmates.

一$.fn.live Repeated binding

Solution:

Use the die() method, Before binding the live() method, unbind all previously bound events on this element, and then bind new events through the live() method.

//先通过die()方法解除,再通过live()绑定 
$("#selectAll").die().live("click",function(){ 
//事件运行代码 
});

Second, unbind the live event

Solution: Use the unbind("click") method to unbind the event first and then bind the new event, that is, giving the object Remove the original event on the object before binding the event

var accoutEdit=function(){ 
            $(this).text("解除绑定事件"); 
            //解除live绑定 
            $('.setAccoutEdit .option').die('click',accoutEdit); 
        } 
  
//绑定修改事件 
$('.setAccoutEdit').live('click',accoutEdit); 
  
/* 关闭 功能*/
$('.editOption').live('click',function(){ 
  
    $(this).text("添加绑定事件"); 
    //添加accoutEdit绑定 
    $('.setAccoutEdit .option').live('click',accoutEdit); 
  
});

In addition
Use bind to bind the event, use unbind to unbind
Use delegate to bind the event, Use undelegate to unbind
Use on-bound events, use off to unbind

The above is the detailed content of Detailed explanation of jQuery live bound events and unbinding examples. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn