如何在< div>上禁用然后启用onclick事件用javascript [英] How to disable and then enable onclick event on <div> with javascript

查看:151
本文介绍了如何在< div>上禁用然后启用onclick事件用javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我正在尝试的代码

Following is the code which i am trying

document.getElementById("id").disabled = true;


推荐答案

您可以使用CSS属性 pointer-events 禁用任何元素上的click事件:

You can use the CSS property pointer-events to disable the click event on any element:

https://developer.mozilla.org/en-US/docs/Web/CSS/pointer-events

// To disable:    
document.getElementById('id').style.pointerEvents = 'none';
// To re-enable:
document.getElementById('id').style.pointerEvents = 'auto'; 
// Use '' if you want to allow CSS rules to set the value

这里使用''是一个JsBin: http://jsbin.com/oyAhuRI/1/edit

Here is a JsBin: http://jsbin.com/oyAhuRI/1/edit

这篇关于如何在< div>上禁用然后启用onclick事件用javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆