使用JavaScript动态的绑定、解绑 a 标签的onclick事件,防止重复点击

页面上的 a 标签如下:
<a class="more" style="cursor: pointer;" id="commentMore"
    onclick="javascript:selectMoreComment(this.id,2018);">查看更多</a>
页面操作元素的js代码:
function selectMoreComment(id, selectVal){
    document.getElementById(id).onclick = null; // 解绑onclick事件
	
	alert("点击事件已经取消,当前业务处理完后再把点击事件加上,可以防止数据加载期间用户的重复点击操作!")
	
	// 绑定onclick点击事件
	document.getElementById(id).onclick = function () {
		selectMoreComment(id, selectVal)
	}
}
posted @ 2018-09-05 09:46  DaleyZou  阅读(4332)  评论(0编辑  收藏  举报