清空文本框所有内容

转自:http://blog.csdn.net/zhengqiqiqinqin/article/details/9302527

js或者jquery清空文本框所有内容

reset只能重置文本框的内容,有时候不满足我们的需求,可以使用如下方法进行清空文本框的内容:

jquery实现:

[javascript]  view plain copy
  1. "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2. "http://www.w3.org/1999/xhtml">  
  3.   
  4. "Content-Type" content="text/html; charset=utf-8" />  
  5. 无标题文档  
  6. "text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">  
  7. "text/javascript">  
  8. $(document).ready(function(){  
  9.  $(function(){  
  10.    $('input:reset').click(function(){  
  11.      $('.input').val("");  
  12.     });  
  13.   });  
  14.   });  
  15.   
  16.   
  17.   
  18. "72" class="input" maxlength="64" name="aaa" type="text" value="nihao">  
  19. "72" class="input" maxlength="64" name="bbb" type="text" value="nihao2">  
  20. "72" class="input" maxlength="64" name="ccc" type="text" value="nihao3">  
  21. "清空全部" onClick="" type="reset">  
  22.   
  23.   

javascript实现:只清空input的type 是text 文本框的内容

[javascript]  view plain copy
  1. "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2. "http://www.w3.org/1999/xhtml">  
  3.   
  4. "JavaScript">  
  5.     function doReset(){  
  6.     for(i=0;i"input").length;i++){  
  7.         if(document.all.tags("input")[i].type=="text"){  
  8.             document.all.tags("input")[i].value="";  
  9.         }  
  10.     }  
  11. }  
  12.   
  13.   
  14.      
  15.   
  16. "72" class="input" maxlength="64" name="aaa" type="text" value="nihao">  
  17. "72" class="input" maxlength="64" name="bbb" type="text" value="nihao2">  
  18. "72" class="input" maxlength="64" name="ccc" type="text" value="nihao3">  
  19. "清空全部" onClick="doReset()" type="button">  
  20.   
  21.   

你可能感兴趣的:(web前端开发)