且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

jQuery:如何获取表单提交时点击哪个按钮?

更新时间:2022-12-17 19:44:57

我问了同样的问题:如何获得导致从表单提交事件提交的按钮?

我最终提出了这个解决方案,它工作得很好:

I ended up coming up with this solution and it worked pretty well:

$(document).ready(function() {
    $("form").submit(function() { 
        var val = $("input[type=submit][clicked=true]").val();
        // DO WORK
    });
    $("form input[type=submit]").click(function() {
        $("input[type=submit]", $(this).parents("form")).removeAttr("clicked");
        $(this).attr("clicked", "true");
    });
});






在您使用多个表单的情况下,您可能需要调整这一点,但它应该仍然适用


In your case with multiple forms you may need to tweak this a bit but it should still apply