/** * js获取表单里的参数并返回键值对 * @version 1 * @param {Object} - js表单对象 * @returns {Object} - 表单参数键值对 */ function getFormData(form){ if (!form) { return {}; } var params = {} , elems = form.elements ; for(var i in elems){ var elem = elems[i]; if(elem.nodeName != "INPUT"){ continue; } var nodeAttrs = elem.attributes; if(nodeAttrs.name){ params[nodeAttrs.name.nodeValue] = elem.value; } } return params; } // eg var p = getFormData(document.forms[0]); // p.a = 1 // p.b = 2 // p.c = 3
Last Modified: 2017-12-21 16:02:44