form的序列化,即将表单中的键值序列化为可提交的字符串
表单
passsword
Football
Box" name="hobby" value="basketball"> Basketball
Female
dio" name="sex" value="Male"> Male
方法一
结果:
方法二
属性,有的话返回true,若定义了此属性但尚未添加到元素中也返回true。
optionValue = option.value;
} else {
optionValue = optionValue.text;
}
parts.push(encodeURIComponent(field.name) + '=' + encodeURIComponent(optionValue));
}
}
}
break;
case undefined:
case 'file':
case 'submit':
case 'reset':
case 'button':
break;
case 'radio':
case 'checkBox':
if(!field.checked){
break;
}else{
parts.push(encodeURIComponent(field.name) + '=' + encodeURIComponent(field.dataset['index']));
break;
}
default:
if(field.name.length){
parts.push(encodeURIComponent(field.name) + '=' + encodeURIComponent(field.value));
}
}
}
return parts.join('&');
}
// 调用
var oForm = document.getElementById('target');
console.log(serializeForm2(oForm));
结果:
方法三
dio'|'checkBox']/g;
var reg3=/['select']/g;
if(reg1.test(tagType)){
res.push(encodeURIComponent(tagName)+"="+encodeURIComponent(tagVal));
}else if(reg2.test(tagType)&&tag.checked){
res.push(encodeURIComponent(tagName)+"="+encodeURIComponent(tagVal));
}else if(reg3.test(tagType)){
for(var j=0;j// 调用
var oForm = document.getElementById('target');
console.log(serializeForm3(oForm));
var oForm = document.getElementById('target');
console.log(serializeForm3(oForm));
结果:
内容啦,希望对大家有所帮助~