How can I find the button that was clicked from the form to send an event to jquery?

I have a function that I use to prevent multiple form backs:

var submitted = false;
$(function() {
    $('form').bind('submit', function(e) {
        if (!submitted && CanSubmit(e)) {
            submitted = true;
            return true;
        } else {
            return false;
        }
    });
});

In the method, CanSubmitI need to interrogate the button that the button was pressed to determine whether I should allow sending or not.

Please note that I cannot be attached to specific click events - see this previous question for more details.

In Firefox, I can use e.originalEvent.explicitOriginalTarget, but this is apparently not available in IE.

How can I get this value from a parameter ein a browser?

+5
4

$('form').bind('submit' $(':submit').bind('click', ( this, , ).

+2

e.target - jQuery .

, explicitOriginalTarget, document.activeElement ( IE) - , . webkit- . , , .

+2

? :

$(function() {
    $('form').bind('submit', function(event) {
          // regular submit form stuff here
        ...
          // and unbind it
        $('this').unbind(event);       
    });
});

. unbind() " "

, , .one(), .

$(function() {
    $('form').one('submit', function(event) {           // <== Only executed once
          // regular submit form stuff here
        ...
    });
});

$.post() $.get() , /, , event, . , .

+2

.one, , .

$(function() {
    $('form').one('submit', function(event) {
      // regular submit form stuff here     
    });
});
0

All Articles