我天真的方法如下:
function isClickable(id){
elem = document.getElementById(id);
if (elem.nodeName.toLowerCase() == 'a' || typeof(elem.click) != 'undefined'){
return true;
}else{
return false;
}
}
我还能做些什么更好的事情吗?
对于大多数元素...
if(e.getAttribute('onclick')!=null){
// clickable
}
对于锚...
if(e.getAttribute('href')!=null){
// clickable
}
然后你有需要更多代码的表单按钮,最后你有点击事件冒泡来处理,所以覆盖所有元素的完美解决方案将是一场噩梦!
但是,如果您只想要简单的容器和锚点,那么我们可以将上面的逻辑与......
if((e.getAttribute('onclick')!=null)||(e.getAttribute('href')!=null)){
// clickable
}
对于相反...
if((e.getAttribute('onclick')===null)&&(e.getAttribute('href')===null)){
// not clickable
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)