解决form表单序列化获取不到未选中的checkbox,radio的值
serialize()对于未选中的checkbox,radio是获取不到值得,我们不可能直接修改源代码,于是我们可以自己实现一个
$.fn.xiubin_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}); } } }); //console.log(a); return jQuery.param(a); };怎么引用呢?$(form).ghostsf_serialize();即可
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。

