功能代码类似如下,有个表单,通过调用简单的方式实现 在客户端清空值
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1
2
<
form
id
="form1"
method
="post"
>
3 < input type ="text" />
4 < input type ="text" />
5 < input type ="button" value ="clear" onclick ="Refresh()" />
6 </ form >
7
8
9 通过调用js的Refresh方法
10
11
12 方法一
13
14 function Refresh()
15 {
16
17 var v=document.forms[0].elements;
18 for(var i=0;i < v .length;i++)
19 {
20 if(v[i].type =="text")
21 {
22 v[i].value ="" ;
23 }
24 }
25
26 }
27
28 或方法二
29
30
31 function Refresh()
32 {
33 var v =document.getElementsByTagName("input");
34 for(var i =0;i<v.length;i++)
35 {
36 if(v[i].type =="text")
37 {
38 v[i].value ="" ;
39 }
40 }
41
42 }
43
44 通过调用refresh函数清空某种元素的值
45
3 < input type ="text" />
4 < input type ="text" />
5 < input type ="button" value ="clear" onclick ="Refresh()" />
6 </ form >
7
8
9 通过调用js的Refresh方法
10
11
12 方法一
13
14 function Refresh()
15 {
16
17 var v=document.forms[0].elements;
18 for(var i=0;i < v .length;i++)
19 {
20 if(v[i].type =="text")
21 {
22 v[i].value ="" ;
23 }
24 }
25
26 }
27
28 或方法二
29
30
31 function Refresh()
32 {
33 var v =document.getElementsByTagName("input");
34 for(var i =0;i<v.length;i++)
35 {
36 if(v[i].type =="text")
37 {
38 v[i].value ="" ;
39 }
40 }
41
42 }
43
44 通过调用refresh函数清空某种元素的值
45