Use native js
- The anonymous function assigned to the event null;
onload = function (){
var a = document.getElementById("a");
//注册事件
a.onclick = function (){
console.log("a")
}
//事件解绑
a.onclick = null;
}
Using jQuery
- To register an event on the method of use jquery
$(function (){
//使用jQuery注册事件 a是我的类选择器
$(".a").on("click",function (){
console.log("a");
})
//也可以不使用on方法
$(".a").click(function (){
console.log("a")
})
})
- Unbundling event to use off method in jquery
//解绑事件
$(".a").off("click")