jquery自定义属性添加点击事件

html:

  `<button list-event="export_list">导出</button>`

js代码

/*A.call(B,x,y)

1、改变函数A的this指向,使之指向B;

2、 把A函数放到B中运行,x和y是A函数的参数。*/
var car_data = {
	init : function (){
		 //点击事件
		$('body').on('click', '*[list-event]', function(e){
			var othis = $(this), methid = othis.attr('list-event');
			car_events[methid] ? car_events[methid].call(this, othis, e) : '';
			return false;
			cancelBubble ();
		});
	}
}

var car_events = {
	//事件名
	export_list : function (othis,e) {
	      console.log(othis)
	}
}
posted @ 2020-11-17 13:27  kilig-wu  阅读(1053)  评论(0编辑  收藏  举报