How can I serializeArray for unchecked checkboxes?

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

    @SNag's answer worker almost 99% just with little bit correction. Change below line

    from :

    $.each(this, function (i, e) {
    

    to:

    $.each(this.find('input'), function (i, e) {
    

    Explanation: As this was not working because this returned form element. So on form .each won't give us all input elements inside form. So I did this correction and it worked like charm.

提交回复
热议问题