开发者

Use jQuery to unbind a click handler that wasn't added with jQuery?

I want to use jQuery to r开发者_如何学Goemove a click event handler that wasn't added with jQuery. For example:

<a onclick="alert('This was set by onclick.')" href="#">Click me</a>

<script type="text/javascript">
  $(document).ready(function(){
    $("a").unbind(); // Why isn't this working?
    $("a").click(function(event){
      alert("This was set by jquery click.");
    });
  });
</script>

Is this possible? $("a").unbind() isn't working. The above code displays both alert() windows and not just the one added by jQuery. I think unbind() only unbinds handlers which were bound with bind().


Try removeAttr instead:

$('a').removeAttr('onclick');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜