首页 > Web开发 > 详细

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

时间:2021-03-31 16:20:25      阅读:26      评论:0      收藏:0      [点我收藏+]

参数处理对象

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

对象转字符串

表单序列化
在 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(){}

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!