在 jQuery 中,fn的意思,$.fn.serializeObject = function(){}

参数处理对象

序列化和反序列化
字符串转对象

对象转字符串

表单序列化
在 jQuery 中,fn 其实就是 JavaScript 中 propotype 的一个别名,$ 是 jQuery 的别名,

所以$.fn.pluginName 等同于 jQuery.prototype.pluginName

举例

/**将表单转换为json对象*/
$.fn.serializeObject = function() {
var o = {};
var a = this.serializeArray();
$.each(a, function() {
if (o[this.name]) {
if (!o[this.name].push) {
o[this.name] = [ o[this.name] ];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
};

使用:var jsonObj = $("#" + formid).serializeObject();

原文地址:https://www.cnblogs.com/BabyRui/p/14600862.html