在 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();

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

上一篇:Linux Centos8通过 Snap 安装 .NET SDK 或 .NET Runtime的解决办法


下一篇:微信支付之扫码支付、公众号支付、H5支付、小程序支付相关业务流程分析总结