首页 > Web开发 > 详细

jQuery序列化后的表单值转换成Json

时间:2016-09-02 11:23:45      阅读:310      评论:0      收藏:0      [点我收藏+]
$.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;
};


var jsonObj = $("#form").serializeObject(); //json对象

var jsonStr = JSON.stringify($("#form").serializeObject()); //json字符串

jQuery序列化后的表单值转换成Json

原文:http://www.cnblogs.com/chenweichu/p/5832633.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!