首页 > 技术文章 > 序列化问题

beimingbingpo 2018-10-09 11:14 原文

serialize()对于未选中的checkbox,radio是获取不到值得。

$.fn.all_serialize = function () { var a = this.serializeArray(); var $radio = $('input[type=radio],input[type=checkbox]', this); var temp = {}; $.each($radio, function () { if (!temp.hasOwnProperty(this.name)) { if ($("input[name='" + this.name + "']:checked").length == 0) { temp[this.name] = ""; a.push({name: this.name, value:0}); } } }); return a; }; $("#form_id").all_serialize();

 

推荐阅读