当前位置:Gxlcms > JavaScript > javascript客户端遍历控件与获取父容器对象示例代码_javascript技巧

javascript客户端遍历控件与获取父容器对象示例代码_javascript技巧

时间:2021-07-01 10:21:17 帮助过:23人阅读

1,遍历也面中所有的控件
function findControlAll()
{
var inputs=document.getElementsByTagName("input");
for(j=0;j if(inputs[j].type=="text") //这儿将页面所有类型为text的控件找出来,也可以设置成你想遍历的控件类型
{
inputs[j].value=""; //清空文本框的内容
}
}
2,遍历指定容器中的控件
function findControl()
{
//下面的table1是指遍历该table中的控件
var inputs = document.getElementById("table1").getElementsByTagName("input");
for(var i=0;i {
if(inputs[i].type=="text")//和上面的一样,控件的类型和所要做的操作可根据需要填写
{
inputs[i].value="";
}
}
}

获取父容器对象

代码如下:



function CheckBoxAll(e){
//parentNode 是获取上级属性
var obj = e.parentNode.parentNode.parentNode.getElementsByTagName("*");}

人气教程排行