document.all.item作用

1、document.all.myCheckBox和 document.all.item通过控件的名字定位控件,item()中是控件的名字
例如:
<input type="checkbox" name="myCheckBox">
可以用
document.all.myCheckBox得到这个控件,也可以写成document.all.item("myCheckBox")
用item的好处是,
1.如果你的控件的name是数字,比如<br>
<input type="checkbox" name="123456789">
,使用document.all.123456789会报错,用document.all.item("123456789")可以正确得到。
2.如果你的控件名字存在一个变量中,你必须这样写
var name = "myCheckBox";
eval("document.all."+name);
同样也可以写成document.all.item(name)
<form name="form1">
<input id="a" name="a" type="text" value="123123213">
</form>
<script language="javascript">
document.write(document.form1.a.value);
document.write("<br>");
document.write(document.all.item("a").value);
</script>


2、一个form同时提交到两个页面的效果,工作的需要,随手记了下来!
<script language="javascript">
function F_submit(){
document.form1.target="_blank";
document.form1.action="1.asp";
document.form1.submit();
document.form1.target="_blank";
document.form1.action="2.asp";
document.form1.submit();
}
</script>
<form name="form1" method="post" action="">
<input type="text" name="textfield">
<input type="button" name="Submit" value="提交" onClick="F_submit()">
</form>

posted @ 2017-08-01 09:11  天晴微笑  阅读(290)  评论(0编辑  收藏  举报