看下面的html:同志们请注意,IE下获取不到name为abc的input元素<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
<title></title>
<script type="text/javascript">
function test(e){
alert(document.getElementById('txt12').name);
}
</script></head>
<body onload="test()">
<form>
<input name="txt12" type="text" style="width:95%;height:100%;font-family: 宋体;font-size:9pt;color:Gray;" runat="server" value="自动编号" readonly="readonly"/>
<input id="txt12" name='abc' type="text" style="width:95%;height:100%;font-family: 宋体;font-size:9pt;color:Gray;" runat="server" value="自动编号" readonly="readonly"/>
</form>
</body>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
<title></title>
<script type="text/javascript">
function test(e){
alert(document.getElementById('txt12').name);
}
</script></head>
<body onload="test()">
<form>
<input name="txt12" type="text" style="width:95%;height:100%;font-family: 宋体;font-size:9pt;color:Gray;" runat="server" value="自动编号" readonly="readonly"/>
<input id="txt12" name='abc' type="text" style="width:95%;height:100%;font-family: 宋体;font-size:9pt;color:Gray;" runat="server" value="自动编号" readonly="readonly"/>
</form>
</body>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
<title></title>
<script type="text/javascript">
function test(e){
alert(document.getElementById('txt12').name);
}
</script></head>
<body onload="test()">
<form>
<input name='txt12' type='text'/>
<input id="txt12" name='abc' type='text'/>
</form>
</body>
</html>PS:不知道是不是我的IE8有问题,看navigator.userAgent.toLowerCase();显示的是:
mozilla/4.0 (compatible; msie 8.0; windows nt 5.1; trident/4.0; infopath.2; .net clr 2.0.50727)但IE8以下是有错的,类似15楼的同学,请你们多看看前面别人的发言,再多试试再发言,谢谢!
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
<title></title>
<script type="text/javascript">
function test(e){
alert(document.getElementById('txt12').getAttribute("name"));
}
</script></head>
<body onload="test()">
<form>
<input name="txt12" type="text" style="width:95%;height:100%;font-family: 宋体;font-size:9pt;color:Gray;" runat="server" value="自动编号" readonly="readonly"/>
<input id="txt12" name='abc' type="text" style="width:95%;height:100%;font-family: 宋体;font-size:9pt;color:Gray;" runat="server" value="自动编号" readonly="readonly"/>
</form>
</body>
</html>
那你就试试嘛,尴尬了……这种情况下,低版本的IE是获取不到对应的那个input的,就像三石说的,是个bug