jQuery / HTML - 禁用OnClick [英] jQuery/HTML - Disable OnClick

查看:153
本文介绍了jQuery / HTML - 禁用OnClick的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

display:block; opacity:0.89;>< / div>

这个

div是从外部脚本加载的,因此我看不到特定的代码。

我试图删除这个

  $(#test)。click(function(){return false}); 
$(#test)。unbind();
$(#test)。removeAttr(onclick);
//建议不起作用
$('#test')。on('click',function(e){e.preventDefault(); return false;});
$(#test)。click(function(event){
event.preventDefault();
});

以上都不是。



编辑:解决我的问题使用.unbind(点击);在创建div之后。

解决方案

您可以添加 off(click);



小提琴

  $(function(){
$(#test)。click(function(){alert('test');}) ;
$(#test)。off('click');

});

这段代码将演示删除以前添加的点击事件。


as the title says I'm trying to disable OnClick for specific

<div id="test" style="display: block; opacity: 0.89;"></div>

this div is loaded from external script which is obfuscated so i cannot see the specific code.

What I have tried to remove this

$("#test").click(function(){ return false});
$("#test").unbind();
$("#test").removeAttr("onclick");
//Suggestions which do not work
$('#test').on('click', function(e) {e.preventDefault();return false;});
$("#test").click(function(event){
event.preventDefault();
});

None of the above work.

EDIT: Solved my problem using .unbind("click"); after the div was created.

解决方案

You can add off("click");

Fiddle

$(function () {
    $("#test").click(function(){alert('test');});
    $("#test").off('click');

});

this code will demonstrate removing a previously added click event.

这篇关于jQuery / HTML - 禁用OnClick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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