码迷,mamicode.com
首页 > Web开发 > 详细

使用jquery将表单自动封装成json对象 /json对象元素的添加删除和转换

时间:2017-05-19 11:11:27      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:orm   this   cti   idt   height   class   tar   开心   function   

  1. $.fn.serializeObject = function () {  
  2.         var o = {};  
  3.         var a = this.serializeArray();  
  4.         $.each(a, function () {  
  5.             if (o[this.name]) {  
  6.                 if (!o[this.name].push) {  
  7.                     o[this.name] = [o[this.name]];  
  8.                 }  
  9.                 o[this.name].push(this.value || ‘‘);  
  10.             } else {  
  11.                 o[this.name] = this.value || ‘‘;  
  12.             }  
  13.         });  
  14.         return o;  
  15.     };  
  16. var formData = $("#editForm").serializeObject();  

var json={
   id:"id1",
   name:"开心"
};
 
//添加
json["gender"]="男"
json["age"]=26;
alert(json.age);
 
//删除
delete json["age"];
alert(json.age);
alert(json.gender);

  1. $.fn.serializeObject = function () {  
  2.         var o = {};  
  3.         var a = this.serializeArray();  
  4.         $.each(a, function () {  
  5.             if (o[this.name]) {  
  6.                 if (!o[this.name].push) {  
  7.                     o[this.name] = [o[this.name]];  
  8.                 }  
  9.                 o[this.name].push(this.value || ‘‘);  
  10.             } else {  
  11.                 o[this.name] = this.value || ‘‘;  
  12.             }  
  13.         });  
  14.         return o;  
  15.     };  

使用jquery将表单自动封装成json对象 /json对象元素的添加删除和转换

标签:orm   this   cti   idt   height   class   tar   开心   function   

原文地址:http://www.cnblogs.com/yangpeng-jingjing/p/6877078.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!