document.forms['form1']和document.form1有什么区别?
在asp.net页面自动生成的JS代码中看到了这样的代码:
if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
theform = document.forms["Form1"];
}
else {
theform = document.Form1;
}
从代码来看,应该是判断如果是网景浏览器,就执行theform = document.forms["Form1"]; 否则就执行else中的内容。
应该是为了解决浏览器差异而写的,但是我做了测试:
写一个JS方法
function doTest()
{
alert(document.forms["form1"]);
alert(document.form1);
}
再用一个按钮来调用它
<input id="ButtonTest" type="button" value="DifferentTest" onclick="doTest()"/>
在IE中执行这个测试,谈出了两次Object,也就是说两种方式都能获取到form1,那么为什么在asp.net中还要自动生成判断是否为网景浏览器的代码呢?恳请指点!