将 表单 数据 序列化 为 js对象

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010690818/article/details/79917809
    $.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;
    }

猜你喜欢

转载自blog.csdn.net/u010690818/article/details/79917809