有与onclick事件行动预防的onclick行动与jQuery
<a href="#" onclick="alert('panic!')">Let's panic</a>
<a href="#" onclick="alert('panic!')" disabled="disabled">I can't panic no more</a>
我需要防止链接事件阿克顿斯执行与残疾人属性而没有删除的onclick行动,一些链接。
$('a[disabled]').click(function(e){
e.stopPropagation();
return false;
});
此代码不能帮助我。
更新即使这个代码不起作用
<html><head><script type='text/javascript' src='jquery-1.3.2.js'></script></head>
<body>
<a href='#' onclick="alert('HA-ha!')" disabled="disabled" class="disabled">TEST</a>
<script type="text/javascript">
$('a[disabled], a.disabled').click(function(e){
console.log('override?');
e.stopImmediatePropagation();
e.preventDefault();
e.stopPropagation();
return false;
});
</script>
</body></html>
所有的jQuery代码应该被包裹在一个'$(文件)。就绪(函数(){...代码在这里...});'也就是说,与来自移除'disabled'标签组合的标记和选择器应该能够正常工作。 – rfunduk 2009-11-18 14:58:32
'返回false;''主场迎战e.preventDefault();''VS e.stopPropagation();'的讨论在这里找到:http://stackoverflow.com/questions/1357118/javascript-event-preventdefault-vs-return -false – 2009-11-18 14:52:17