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

后端 未结 10 877
暖寄归人
暖寄归人 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

    I did the following, finding the unchecked checkboxes, checking them before calling serializeArray, then unchecking them so the form would be in the same state as the user left it:

    var unchecked = chartCfgForm.find(':checkbox:not(:checked)');
    unchecked.each(function() {$(this).prop('checked', true)});
    var formValues = chartCfgForm.serializeArray();
    unchecked.each(function() {$(this).prop('checked', false)});
    

提交回复
热议问题