复制代码 代码如下:
//清空form选择
function clearForm(id){
var formObj = document.getElementById(id);
if(formObj == undefined){
return;
}
for(var i=0; i<formObj.elements.length; i++){
if(formObj.elements[i].type == "text"){
formObj.elements[i].value = "";
}
else if(formObj.elements[i].type == "password"){
formObj.elements[i].value = "";
}
else if(formObj.elements[i].type == "radio"){
formObj.elements[i].checked = false;
}
else if(formObj.elements[i].type == "checkbox"){
formObj.elements[i].checked = false;
}
else if(formObj.elements[i].type == "select-one"){
formObj.elements[i].options[0].selected = true;
}
else if(formObj.elements[i].type == "select-multiple"){
for(var j = 0; j < formObj.elements[i].options.length; j++){
formObj.elements[i].options[j].selected = false;
}
}
else if(formObj.elements[i].type == "file"){
//formObj.elements[i].select();
//document.selection.clear();
// for IE, Opera, Safari, Chrome
var file = formObj.elements[i];
if(file.outerHTML){
file.outerHTML = file.outerHTML;
}else{
file.value = ""; // FF(包括3.5)
}
}
else if(formObj.elements[i].type == "textarea"){
formObj.elements[i].value = "";
}
}
}
//清空form选择
function clearForm(id){
var formObj = document.getElementById(id);
if(formObj == undefined){
return;
}
for(var i=0; i<formObj.elements.length; i++){
if(formObj.elements[i].type == "text"){
formObj.elements[i].value = "";
}
else if(formObj.elements[i].type == "password"){
formObj.elements[i].value = "";
}
else if(formObj.elements[i].type == "radio"){
formObj.elements[i].checked = false;
}
else if(formObj.elements[i].type == "checkbox"){
formObj.elements[i].checked = false;
}
else if(formObj.elements[i].type == "select-one"){
formObj.elements[i].options[0].selected = true;
}
else if(formObj.elements[i].type == "select-multiple"){
for(var j = 0; j < formObj.elements[i].options.length; j++){
formObj.elements[i].options[j].selected = false;
}
}
else if(formObj.elements[i].type == "file"){
//formObj.elements[i].select();
//document.selection.clear();
// for IE, Opera, Safari, Chrome
var file = formObj.elements[i];
if(file.outerHTML){
file.outerHTML = file.outerHTML;
}else{
file.value = ""; // FF(包括3.5)
}
}
else if(formObj.elements[i].type == "textarea"){
formObj.elements[i].value = "";
}
}
}
标签:
js,清空,form表单
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
狼山资源网 Copyright www.pvsay.com
暂无“js清空form表单中的内容示例”评论...