序列化form表單
阿新 • • 發佈:2019-01-02
// 序列化JSON字串 $.fn.serializeObject = function () { let o = {}; let a = this.serializeArray(); $.each(a, function () { let value = this.value; let chain = this.name.split("."); let c = o; $.each(chain, function (i, e) { if (i === (chain.length - 1)) { if (c[e]) { if (!c[e].push) { c[e] = [c[e]]; } c[e].push(value || ''); } else { c[e] = value || ''; } } else { if (!c[e]) { c[e] = {}; } } c = o[e]; }); }); return o; };