How can I serializeArray for unchecked checkboxes?

前端 未结 12 831
耶瑟儿~
耶瑟儿~ 2021-02-05 08:01

How can I modify this example so it can get values from checkboxes that aren\'t checked?

I want all checkboxes to have a value, if it hasn\'t been checked I want to get

12条回答
  •  梦如初夏
    2021-02-05 08:25

    var fields = $("form").serializeArray();
    $('form input[type=checkbox]').map(function() {
       if( !this.checked )
            {
                    fields.push({ name: this.name, value: "off" });
            }
       });
    

提交回复
热议问题