同自定义属性委派的事件,查找速度较快,当然在事件的触发过程中也要注意事件的冒泡,和捕获,这些有时候会造成一些负面影响。
<button type="button" oper="myBtn"></button>
$("body").on("click",'[oper]',function(e){
let _this = $(this);
let type = _this.attr('oper');
e.stopPropagation();//阻止事件冒泡
switch(type){
case "myBtn":
console.log("委派成功!")
break;
}
})