您的位置:首页 > Web前端 > JQuery

jquery 实现表单数据转化为对象格式

2017-07-24 11:18 260 查看
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();

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: