您想要禁用页面上的所有onclick事件 我写这个:
window.onclick = anyfunction;
document.onclick=anyfunction;
function anyfunction() {};
这是有效的,但如果页面包含此代码
$("body").click(function () {
anyfunctions();
});
它会运行。 即使我添加
document.body.onclick
Jquery代码再次运行。 我想用javascript禁用所有onclick函数(java脚本和jquery和...)而不使用jquery库
目标是阻止弹出窗口 感谢
答案 0 :(得分:3)
$("*").unbind("click"); // Removes all click handlers added by javascript from every element
$("[onclick]").removeAttr("onclick"); // Finds all elements with an 'onclick' attribute, and removes that attribute
答案 1 :(得分:3)
这个CSS可能会以更好的方式帮助你。
function disableEvents()
{
$('#divname').css('pointer-events','none');
}
无论您何时想要停止页面上的点击事件,都可以随时调用此功能。这将有效。
答案 2 :(得分:0)
您也可以尝试
$('*').click(function(e){e.preventDefault();});