unbind()--unbind(type,data)javascript
第一個參數事件類型,第二個參數將要移除的函數html
(1)、若是沒有參數,則刪除全部綁定的函數java
(2)、若是隻提供了事件類型做爲參數,則只刪除該類型的綁定事件jquery
(3)、若是把在綁定時傳遞的處理函數做爲第二個參數,則只有這個特定的事件處理函數會被刪除app
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <script type="text/javascript" src='jquery-3.2.1.min.js'></script> <script type="text/javascript"> $(function(){ $('#btn').bind('click',fn1=function(){ $('#test').append('<p>個人綁定函數1</p>'); }).bind('click',fn2=function(){ $('#test').append('<p>個人綁定函數2</p>'); }).bind('click',fn3=function(){ $('#test').append('<p>個人綁定函數3</p>'); }); $('#delAll').click(function() { $('#btn').unbind('click',fn2); }); }); </script> </head> <body> <button id="btn">單擊我</button> <button id="delAll">刪除全部事件</button> <div id="test"></div> </body> </html>
one()--該方法能夠爲元素綁定處理函數,當處理函數觸發一次後,當即被刪除函數
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <script type="text/javascript" src='jquery-3.2.1.min.js'></script> <script type="text/javascript"> $(function(){ $('#btn').one('click',function(){ $('#test').append('<p>個人綁定函數1</p>'); }).one('click',function(){ $('#test').append('<p>個人綁定函數2</p>'); }).one('click',function(){ $('#test').append('<p>個人綁定函數3</p>'); }); }); </script> </head> <body> <button id="btn">單擊我</button> <button id="delAll">刪除全部事件</button> <div id="test"></div> </body> </html>