良玉的博客 点点滴滴,积水成河_良玉的博客_页游、手游linux运维工程师之路

js清空form表单中的内容

line-height: 26px; white-space: normal; margin: 18px 0px !important; background-color: rgb(231, 229, 220);">
[javascript] url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); background-attachment: initial; background-color: inherit; background-size: initial; background-origin: initial; background-clip: initial; background-position: 0% 0%; background-repeat: no-repeat;">view plaincopy查看代码片" style="color: rgb(160, 160, 160); text-decoration: none; border: none; padding: 1px; margin: 0px 10px 0px 0px; font-size: 9px; display: inline-block; width: 16px; height: 16px; background-image: none; background-attachment: initial; background-color: inherit; background-size: initial; background-origin: initial; background-clip: initial; background-position: 0% 0%; background-repeat: no-repeat;">在CODE上查看代码片https://code.csdn.net/snippets/354656/fork" target="_blank" title="派生到我的代码片" style="color: rgb(160, 160, 160); text-decoration: none; border: none; padding: 1px; margin: 0px 10px 0px 0px; font-size: 9px; display: inline-block; width: 16px; height: 16px; background-image: none; background-attachment: initial; background-color: inherit; background-size: initial; background-origin: initial; background-clip: initial; background-position: 0% 0%; background-repeat: no-repeat;">派生到我的代码片
  1. //清空form选择  

  2. function clearForm(id){  

  3.      var formObj = document.getElementById(id);  

  4.     if(formObj == undefined){   

  5.         return;  

  6.     }  

  7.     for(var i=0; i<formObj.elements.length; i++){  

  8.         if(formObj.elements[i].type == "text"){  

  9.             formObj.elements[i].value = "";  

  10.         }   

  11.         else if(formObj.elements[i].type == "password"){   

  12.             formObj.elements[i].value = "";   

  13.         }   

  14.         else if(formObj.elements[i].type == "radio"){   

  15.             formObj.elements[i].checked = false;   

  16.         }   

  17.         else if(formObj.elements[i].type == "checkbox"){   

  18.             formObj.elements[i].checked = false;   

  19.         }   

  20.         else if(formObj.elements[i].type == "select-one"){   

  21.             formObj.elements[i].options[0].selected = true;   

  22.         }   

  23.         else if(formObj.elements[i].type == "select-multiple"){       

  24.             for(var j = 0; j < formObj.elements[i].options.length; j++){   

  25.                 formObj.elements[i].options[j].selected = false;   

  26.             }   

  27.         }   

  28.         else if(formObj.elements[i].type == "file"){   

  29.             //formObj.elements[i].select();   

  30.             //document.selection.clear();                

  31.             // for IE, Opera, Safari, Chrome   

  32.             var file = formObj.elements[i];   

  33.              if(file.outerHTML){   

  34.                  file.outerHTML = file.outerHTML;   

  35.              }else{   

  36.                  file.value = "";  // FF(包括3.5)   

  37.             }   

  38.         }   

  39.         else if(formObj.elements[i].type == "textarea"){   

  40.             formObj.elements[i].value = "";   

  41.         }   

  42.     }  

  43. }  



标签: jsform清空表单

作者:良玉 分类:JS 浏览:741 评论:0
留言列表
发表评论
来宾的头像