How can I serializeArray for unchecked checkboxes?

前端 未结 12 846
耶瑟儿~
耶瑟儿~ 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:24

    serializeArray ignores the checkboxes which are not checked. You can try something like this.

    Working demo

        var serializedObj = {};
        $("form input:checkbox").each(function(){
            serializedObj[this.name] = this.checked;
        });
    

提交回复
热议问题