how can I override jquery's .serialize to include unchecked checkboxes

后端 未结 10 880
暖寄归人
暖寄归人 2020-12-16 14:21

I have read quite a few different methods of having html checkboxes get posted to the server, but I am really looking to do it without modifying anything except for $.serial

10条回答
  •  不知归路
    2020-12-16 14:41

    It's a minor change:

        .map(function( i, elem ){
            var val = jQuery( this ).val();
            if ((jQuery(this).checked != undefined) && (!jQuery(this).checked)) {
                val = "false";
            }
    

    I haven't tested but it seems the most logical approach. Good luck

提交回复
热议问题