表单序列化为JSON对象 serializeObject

来源:互联网 发布:淘宝app怎么开店 编辑:程序博客网 时间:2024/05/07 14:17
        //表单序列化为JSON对象
        $.fn.serializeObject = function() {
            var o = {};
            var a = this.serializeArray();
            $.each(a, function() {
                if (o[this.name] !== undefined) {
                    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;
        };
原创粉丝点击