晕,本来上面两个想明白了,再加了一个我又晕了 <HTML> <HEAD> <TITLE> New Document </TITLE> </HEAD> <SCRIPT LANGUAGE="JavaScript"> <!-- function showTagById(){ var a = document.getElementById("abc"); if(a==null){ alert("can't find element."); }else{ alert(a.outerHTML); }} function showTagByName(){ var a = document.getElementsByName("abc"); if(a[0]==null){ alert("can't find element."); }else{ for(var i=0; i<a.length; i++){ alert(a[i].outerHTML); } } } //--> </SCRIPT> <BODY> <a name = "abc">It's Weird, a-name-abc</a> <div id = "abc">It's Weird, div-id-abc</div> <input id = "abc" type=text value="It's Weird, div-id-abc"> <INPUT TYPE="button" value="showTagById" onclick="showTagById();"> <INPUT TYPE="button" value="showTagByName" onclick="showTagByName();"> </BODY> </HTML>
to lunge() 我的问题和你的回答没有关系,我只是说为什么用name取,却把没有设name的element取出来了。
http://www.w3.org/TR/1998/REC-html40-19980424/struct/links.html#anchors-with-id The following example names a destination anchor with the id attribute: I just returned from vacation! Here's a <A id="anchor-two">photo of my family at the lake.</A>. The id and name attributes share the same name space. This means that they cannot both define an anchor with the same name in the same document.
to fantiny(虽然我是菜鸟,不过我是~~非暴力不合作~~的菜鸟)也就是说firefox没有严格按照w3标准来设计了???那么关于div的问题怎么解释???
When you use the IHTMLDocument3::getElementsByName method, all elements in the document that have the specified NAME or ID attribute value are returned.
ID只返回一个对象,就是第一个ID或者NAME为参数的那个对象,NAME返回多个NAME或者ID为参数的那个对象
为什么用name取,也能把tag为div的取出来,而实际上这个tag不具有name属性,而且我也没有设
人生起起伏伏凑字凑
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
function showTagById(){
var a = document.getElementById("abc");
if(a==null){
alert("can't find element.");
}else{
alert(a.outerHTML);
}}
function showTagByName(){
var a = document.getElementsByName("abc");
if(a[0]==null){
alert("can't find element.");
}else{
for(var i=0; i<a.length; i++){
alert(a[i].outerHTML);
}
}
}
//-->
</SCRIPT>
<BODY>
<a name = "abc">It's Weird, a-name-abc</a>
<div id = "abc">It's Weird, div-id-abc</div>
<input id = "abc" type=text value="It's Weird, div-id-abc">
<INPUT TYPE="button" value="showTagById" onclick="showTagById();">
<INPUT TYPE="button" value="showTagByName" onclick="showTagByName();">
</BODY>
</HTML>
The following example names a destination anchor with the id attribute: I just returned from vacation! Here's a
<A id="anchor-two">photo of my family at the lake.</A>.
The id and name attributes share the same name space. This means that they cannot both define an anchor with the same name in the same document.
难道真是w3的标准??
它到底要干什么?
ie接口这么设计,我觉得是microsoft偷懒吧。