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()
;即可