JS how to register an event tied to reconciliation Event

Use native js

  1. 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

  1. 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")
	})
})
  1. Unbundling event to use off method in jquery
//解绑事件
	$(".a").off("click")

Guess you like

Origin blog.csdn.net/qq_36949892/article/details/92394731