Value of submit button clicked

后端 未结 6 2141
眼角桃花
眼角桃花 2021-02-07 08:58

This should be really straight forward.

I\'m checking if a form is being submitted using jquery. The form has multiple submit buttons with various values:



        
6条回答
  •  广开言路
    2021-02-07 09:59

    Bind the event to submit buttons instead of the form and then $(this) would have the reference to the buttons...

    $(":submit").live('click', function() {
        alert($(this).val());
    })
    

    EDIT As of jQuery 1.7 live is deprecated. Use on instead.

    $(document).on("click", ":submit", function(e){
        alert($(this).val());
    });
    

提交回复
热议问题