请分别在ie和firefox下执行以下代码,看效果

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<html>
	<body>
	<form id="myform">
		<input type="text" name="haha" />
		<input type="text" name="haha" />
	</form>
	</body>
</html>
<script>
function $(s){
	return document.getElementById(s);
}
var is = $('myform').haha;
for(var i in is){
	alert(i + ':' + is[i].tagName);
}
</script>
Copy Code | Run Code

结果是for in循环在ie下根本得不到要取得表单元素,瀑布汗~