zoukankan      html  css  js  c++  java
  • jquery 实现表单数据转化为对象格式

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

    调用方式:

    获取form表单元素

    1 let obj = $('#listform').serializeObject();
  • 相关阅读:
    嵌入式
    IT 管理
    linux 网络编程 排序
    linux frameBuffer
    虚拟现实
    vc 串口
    OpenGLES 图像
    runloop
    归档
    商标查询
  • 原文地址:https://www.cnblogs.com/summer0319/p/7227968.html
Copyright © 2011-2022 走看看