jQuery: how to get which button was clicked upon form submission?

后端 未结 26 1321
旧巷少年郎
旧巷少年郎 2020-11-22 16:01

I have a .submit() event set up for form submission. I also have multiple forms on the page, but just one here for this example. I\'d like to know which submi

26条回答
  •  囚心锁ツ
    2020-11-22 16:47

    I write this function that helps me

    var PupulateFormData= function (elem) {
    var arr = {};
    $(elem).find("input[name],select[name],button[name]:focus,input[type='submit']:focus").each(function () {
        arr[$(this).attr("name")] = $(this).val();
    });
    return arr;
    };
    

    and then Use

    var data= PupulateFormData($("form"));
    

提交回复
热议问题