jquery override event

与世无争的帅哥 提交于 2019-12-01 02:48:59

Have you tried something like this:

$("a").removeAttr("onclick");

In your case the onCick event is overriding the jQuery one. What you might be able to do is:

$('a').unbind('click').click(function(){
    alert('why hello there children.');
})

But I believe this would have to be included after the

<a href='#' onclick='return showform(this)'>click me</a>

That said, you should really not be using onClicks anyway... it makes the code really hard to maintain and change (as you have found out).

If you're using jQuery like this, you don't want any handlers in the HTML. Can't you just remove the onClick attribute?

If you're worried about breaking stuff, search and replace on:

 onclick='return showform(this)'

and replace with

class='showform'

Then you can do:

$('a.showform').click(function (e) {
    e.preventDefault();
    return showform(this);
});

which will keep your existing handlers working.

There is a plugin for it, but you should only do this when you really need to. The plugin allows you to call the original function or ignore/replace it entirely

jQuery Override Plugin

$(divElementObj).override('onclick', 'click', function(...));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!