How to find the submit button in a specific form in jQuery

后端 未结 7 2324
执念已碎
执念已碎 2020-12-25 09:37

I try to get jQuery object of a submit button in a specific form (there are several forms on the same page).

I managed to get the form element itself. It looks somet

相关标签:
7条回答
  • 2020-12-25 10:35

    This works for me:

    var curSubmit = $("input[type=submit]",this);
    

    where this mean current form submitted

    for ex. to get the name of submitted button and all inputs submitted

    $( "form" ).on( "submit", function( event ) {
        event.preventDefault();
        var data = $(this).serialize(); //all input variables  
        console.log(data); //print data in console
        var submit = $("input[type=submit]",this).attr('name'); 
        alert(submit); // name of submit button
    });
    
    0 讨论(0)
提交回复
热议问题