JS clears the multi text box text field sample code

  • 2020-03-30 02:06:08
  • OfStack

Click the button to clear all the text field of the text box | on the page with Javascript. The code is as follows:
 
<script type="text/javascript"> 
<!-- 
function cls(){ 
var sum=0; 
var t = document.getElementsByTagName("INPUT"); 
for (var i=0; i <t.length;i++){ 
if (t[i].type=='text'){ 
++sum; 
t[i].value="";// empty  
} 
} 
var sum1=0; 
var t1 = document.getElementsByTagName("textarea"); 
for (var i1=0; i1 <t1.length;i1++){ 
if (t1[i1].type=='textarea'){ 
++sum1; 
t1[i1].value="";// empty  
} 
} 
alert(' The page of TEXT:'+sum + '  a n' + ' The page of TextArea:' + sum1 +' a '); 
} 
//--> 
</script> 

Related articles: