在 jQuery 中,fn的意思,$.fn.serializeObject = function(){}
2016-12-28 17:13
323 查看
参数处理对象
序列化和反序列化
字符串转对象
对象转字符串
表单序列化
在 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 其实就是 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();
相关文章推荐
- Objective-C - 多态, 方法的重写, 多态和继承
- Resources.Load();路径和必须用GameObject
- Clang - 是LLVM的前端,可以用来编译C,C++,ObjectiveC等语言
- Objective-c - 私有属性和私有方法的应用
- 友盟分享报错_OBJC_CLASS_$_QQApiImageArrayForQZoneObject
- CreateEvent WaitForSingleObject
- error C2220: warning treated as error - no object file generated
- [Objective-C]关联(objc_setAssociatedObject、objc_getAssociatedObject、objc_removeAssociatedObjects)
- Java Object Clone
- [GraphQL] Use GraphQL's Object Type for Basic Types
- Object.observe
- Object对象类
- SQLSERVER sysobjects syscolumns
- JavaScript学习 - Object.defineProperty()
- fital:not a valid object name : 'master'
- Objective-c - 私有属性和真私有属性
- object...args参数
- Objective-C中 ==、isEqual、isEqualToString判断字符串相等
- [Paper note] Feature Pyramid Networks for Object Detection
- Objective-C - A类作为B类的属性