84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
我传一个URL和一个form表单元素。生成一个带参数的URL。。。。。。
欢迎选择我的课程,让我们一起见证您的进步~~
仿照着jq写了一个,用法一样的。
function serialize(a, traditional) { var prefix, s = []; if ('[object HTMLFormElement]' === Object.prototype.toString.call(a)) a = a.childNodes; if (["[object Array]", "[object NodeList]"].indexOf(Object.prototype.toString.call(a)) >= 0) { Array.prototype.forEach.call(a, function(v) { if (!v.name || v.disabled) return; if ((v.type === 'radio' || v.type === 'checkbox') && !v.checked) return; add(v.name, v.value); }); } else { for (prefix in a) buildParams(prefix, a[prefix], traditional, add); } return s.join("&"); function add(key, valueOrFunction) { var value = typeof valueOrFunction === 'function' ? valueOrFunction() : valueOrFunction; s[s.length] = encodeURIComponent(key) + "=" + encodeURIComponent(value == null ? "" : value); } function buildParams(t, e, n) { var r; if ("[object Array]" === Object.prototype.toString.call(e)) { Array.prototype.map.call(e, function(e, r) { o(t + "[" + ("object" == typeof e && null !== e ? r : "") + "]", e, n) }); } else if ("[object Object]" === Object.prototype.toString.call(e)) { for (r in e) buildParams(t + "[" + r + "]", e[r], n); } else { n(t, e); } } }
测试,点开看效果:https://jsfiddle.net/ztv676p1/
仿照着jq写了一个,用法一样的。
测试,点开看效果:
https://jsfiddle.net/ztv676p1/