日期:2014-05-16 浏览次数:20645 次
function Serialize(f) {
var params = '', tmp;
for (var i = 0; i < f.elements.length; i++) {
if (f.elements[i].name) {
switch (f.elements[i].type) {
case 'hidden':
case 'password':
case 'text':
case 'textarea':
case 'select-one': params += (params == '' ? '' : '&') + f.elements[i].name + '=' + encodeURIComponent(f.elements[i].value); break;
case 'select-multiple':
tmp = '';
for (var p = 0; p < f.elements[i].options.length; p++)
if (f.elements[i].options[p].selected) tmp += (tmp == '' ? '' : ',') + f.elements[i].options[p].value;
if (tmp != '') params += (params == '' ? '' : '&') + f.elements[i].name + '=' + encodeURIComponent(tmp);
break;
case 'radio':
case 'checkbox':
if (f.elements[i].checked) params += (params == '' ? '' : '&') + f.elements[i].name + '=' + encodeURIComponent(f.elements[i].value); break;
}