简体   繁体   中英

Is there a way to extend a jQuery event handler that is already bound?

I've written a code that clears the form on every reset event like that:

$("form").on("reset", function(event) {
    event.preventDefault();
    $("form").clearForm();
    $("#reportGenerated").empty();
});

This code is inside an external js loaded in every page so this handles the entire system.

In one specific form in my system I have three inputs that loads Ajax requests into another parts of the page, then when I try to reset and clear the form the information provided by the Ajax request isn't cleared.

So my question is, is there a way I can extend my functionality above without being forced to copy/paste what it already does?

I've read the jQuery Event Extension but does not seem to do what I need, plus, is quite "dangerous" to do it if you don't know exactly how every browser and its version handle JavaScript events.

You can easily add another click handler with will run along with this one(no need to do anything in the already existing handler).

$("form").on("reset", function(event) {
    //do your custom stuff here
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM