zoukankan      html  css  js  c++  java
  • 使用jquery将表单自动封装成json对象 /json对象元素的添加删除和转换

    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.     };  
  • 相关阅读:
    渐统江湖的项目原型生成工具 Maven Archetype
    ANT的安装/配置笔记
    Maven服务器安装
    为什么Eclipse替代不了Maven
    Maven入门实战笔记11节[711]
    Maven入门实战笔记11节[15]
    Maven多模块项目中应用maventomcatplugin热部署
    使用 CXF、Spring、Maven 创建一个 SOAP 客户端
    maven2创建的archetypeArtifactId类型大全
    JdbcDaoSupport应用
  • 原文地址:https://www.cnblogs.com/yangpeng-jingjing/p/6877078.html
Copyright © 2011-2022 走看看