Select/submit only changed form fields with jQuery

前端 未结 8 1568
谎友^
谎友^ 2020-12-23 10:45

I\'m looking for a way to submit only changed form fields to the server. So, let\'s say I have a form

8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-23 11:12

    Another option would be to mark the fields as disabled before they are submitted. By default disabled fields will not be serialized or submitted with a default form post.

    Simple example:

    function MarkAsChanged(){
        $(this).addClass("changed");
    }
    $(":input").blur(MarkAsChanged).change(MarkAsChanged);
    
    $("input[type=button]").click(function(){
        $(":input:not(.changed)").attr("disabled", "disabled");
        $("h1").text($("#test").serialize());
    });
    

    on jsfiddle.

提交回复
热议问题