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

后端 未结 10 876
暖寄归人
暖寄归人 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 15:03

    Before you call serialize(), you need to explicitly set the value to false if a checkbox is unchecked

    $(form).find(':checkbox:not(:checked)').attr('value', false);
    

    I have tested it here.

提交回复
热议问题