1 $().extend(‘serialize‘, function () { 2 for (var i = 0; i < this.elements.length; i ++) { 3 var form = this.elements[i]; 4 var parts = {}; 5 for (var i = 0; i < form.elements.length; i ++) { 6 var filed = form.elements[i]; 7 switch (filed.type) { 8 case undefined : 9 case ‘submit‘ : 10 case ‘reset‘ : 11 case ‘file‘ : 12 case ‘button‘ : 13 break; 14 case ‘radio‘ : 15 case ‘checkbox‘ : 16 if (!filed.selected) break; 17 case ‘select-one‘ : 18 case ‘select-multiple‘ : 19 for (var j = 0; j < filed.options.length; j ++) { 20 var option = filed.options[j]; 21 if (option.selected) { 22 var optValue = ‘‘; 23 if (option.hasAttribute) { 24 optValue = (option.hasAttribute(‘value‘) ? option.value : option.text); 25 } else { 26 optValue = (option.attributes(‘value‘).specified ? option.value : option.text); 27 } 28 parts[filed.name] = optValue; 29 } 30 } 31 break; 32 default : 33 parts[filed.name] = filed.value; 34 } 35 } 36 return parts; 37 } 38 return this; 39 });
原文:http://www.cnblogs.com/wanqiu/p/4456324.html