How can I serializeArray for unchecked checkboxes?

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

    Using the jQuery plugin serializeJSON, you can use the data-unchecked-value attribute to specify the value when unchecked:

    
    
    

    JavaScript:

    $('input').serializeJSON({ parseBooleans: true });
    // returns => { 'Check01' : false, 'Check02' : true }
    

提交回复
热议问题