//Javascript 表单序列化
function serializeForm(whichForm)
{
var parts = new Array();
var field = null;
for (var i = 0, len = whichForm.elements.length; i < len; i++)
{
field = whichForm.elements[i];
switch (field.type)
{
case "select-one":
case "select-multipe":
for (var j = 0, optLen = field.options.length; j < optLen; j++)
{
var option = field.options[j];
if (option.selected)
{
var optValue = "";
if (option.hasAttribute)
{
optValue = (option.hasAttribute("value") ? option.value : option.text);
} else {
optValue = (option.attributes["value"].specified ? option.value : option.text);
}
parts.push(encodeURIComponent(field.name) + "=" + encodeURIComponent(optValue));
}
} //
www.jb200.com
break;
case undefined:
case "file":
case "submit":
case "reset":
case "button":
break;
case "radio":
case "
checkbox":
if (!field.
checked)
{
break;
}
default:
parts.push(encodeURIComponent(field.name) + "=" + encodeURIComponent(field.value));
}
}
return parts.join("&");
}