使用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)
	}
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM