将forme表单转换为Json对象

 //将Form 表单转换为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 || '';
                }
            });
            //o 为Json对象
            return o;
        };

方法调用: $('#formSchool').serializeObject()

猜你喜欢

转载自www.cnblogs.com/happygx/p/8876790.html