<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[BIWEB开源PHP WMS系统创始人ArthurXF肖飞的blog]]></title> 
<link>http://www.bizeway.net/index.php</link> 
<description><![CDATA[网务通 - 网务公司发展之路]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[BIWEB开源PHP WMS系统创始人ArthurXF肖飞的blog]]></copyright>
<item>
<link>http://www.bizeway.net/read.php?</link>
<title><![CDATA[getElementById getElementsByName getElementsByTagName]]></title> 
<author>ArthurXF &lt;arthurxf@gmail.com&gt;</author>
<category><![CDATA[Javascript]]></category>
<pubDate>Mon, 08 Sep 2008 14:29:27 +0000</pubDate> 
<guid>http://www.bizeway.net/read.php?</guid> 
<description>
<![CDATA[ 
	getElementById getElementsByName getElementsByTagName 大概介绍 <p>　　getElementById ，getElementsByName ，getElementsByTagName</p><p>　　后两个是得到集合，byid只是得到单个对象</p><p>　　getElementById 的用法</p><p>　　举个例子:</p><p>　　&lt;a id=&quot;link1&quot; name=&quot;link1&quot; href=<u>http://www.kungfuman.net</u>&gt;功夫之王&lt;/a&gt;</p><p>　　同一页面内的引用方法:</p><p>　　<strong>1、使用id:</strong></p><p>　　link1.href，返回值为<u>http://www.kungfuman.net</u></p><p>　　<strong>2、使用name:</strong></p><p>　　document.all.link1.href，返回值为<u>http://www.kungfuman.net</u></p><p>　　<strong>3、使用sourseIndex:</strong></p><p>　　document.all(4).href //注意，前面还有Html、HEAD、TITLE和BODY，所以是4</p><p>　　<strong>4、使用链接集合:</strong></p><p>　　document.anchors(0).href</p><p>　　//全部的集合有all、anchors、applets、areas、attributes、behaviorUrns、bookmarks、boundElements、cells、childNodes、children、controlRange、elements、embeds、filters、forms、frames、images、imports、links、mimeTypes、options、plugins、rows、rules、scripts、styleSheets、tBodies、TextRectangle，请参考MSDN介绍。</p><p>　　其实方法3和方法4是一样使用的集合，只是一个是all，可以包括页面所有标记，而anchors只包括链接。</p><p>　　<strong>5、getElementById:</strong></p><p>　　document.getElementById(&quot;link1&quot;).href</p><p>　　<strong>6、getElementsByName:</strong></p><p>　　document.getElementsByName(&quot;link1&quot;)[0].href //这也是一个集合，是所有name等于该方法所带参数的标记的集合</p><p>　　<strong>7、getElementsByTagName:</strong></p><p>　　document.getElementsByTagName(&quot;A&quot;)[0].href //这也是一个集合，是所有标记名称等于该方法所带参数的标记的集合</p><p>　　<strong>8、tags集合:</strong></p><p>　　document.all.tags(&quot;A&quot;)[0].href</p><p>　　//与方法7一样是按标记名称取得一个集合</p><p>　　除此之外:</p><p>　　event.scrElement可以获得触发时间的标记的引用;</p><p>　　document.elementFromPoint(x,y)可以获得x和y坐标处的元素的引用;</p><p>　　document.body.componentFromPoint(event.clientX,event.clientY)可以获得鼠标所在处元素的引用;</p><p>　　还可以通过元素的父子节点和兄弟节点关系来引用，如nextSibling(当前节点的后一节点)、previousSibling(当前节点的前一节点)、childNodes、children、firstChild、lastChild、parentElement等都是父子节点和兄弟节点的一些引用;还不仅限于此。</p><p>　　上面是同一页面内的常见引用方法，另外还涉及到不同页面中的</p><p>　　getElementsByName返回的是所有name为指定值的所有元素的集合</p><p>　　&ldquo;根据 NAME 标签属性的值获取对象的集合。&rdquo;</p><p>　　集合比数组要松散的多, 集合里每个子项的类型可以不同, 集合只是把某些元素放在一起作为一类来使用, 相比之下数组就严格多了, 每个子项都是统一的类型. document.getElementsByName, document.getElementsByTagName, document.formName.elements 这类方法所得到的结果都是集合.</p><p>　　<strong>例:</strong></p><p>&lt;html&gt; <br /></p><li>&lt;head&gt; <p style="text-indent: 2em">&lt;title&gt;fish&lt;/title&gt; </p><p></p><p style="text-indent: 2em">function get(){ </p><p style="text-indent: 2em">var xx=document.getElementById(&quot;bbs&quot;) </p><p style="text-indent: 2em">alert(&quot;标记名称：&quot;+xx.tagName); </p><p style="text-indent: 2em">} </p><p style="text-indent: 2em">function getElementName(){ </p><p style="text-indent: 2em">var ele = document.getElementsByName(&quot;happy&quot;); </p><p style="text-indent: 2em">alert(&quot;无素为happy的个数：&quot; + ele.length); </p><p style="text-indent: 2em">} </p><p></p><p style="text-indent: 2em">&lt;body&gt; </p><p style="text-indent: 2em">&lt;h2 id=&quot;bbs&quot;&gt;获取文件指定的元素&lt;/h2&gt; </p><p style="text-indent: 2em">&lt;hr&gt; </p><p style="text-indent: 2em">&lt;form&gt; </p><p style="text-indent: 2em">&lt;input type=&quot;button&quot; onclick=&quot;get()&quot; value=&quot;获取标题标记&quot;&gt; </p><p style="text-indent: 2em">&lt;input type=&quot;button&quot; name=&quot;happy&quot; onclick=&quot;getElementName()&quot; value=&quot;click &quot;&gt;&lt;input type=&quot;button&quot; name=&quot;happy&quot; onclick=&quot;getElementName()&quot; value=&quot;click &quot;&gt;&lt;input type=&quot;button&quot; name=&quot;happy&quot; onclick=&quot;getElementName()&quot; value=&quot;click &quot;&gt;&lt;input type=&quot;button&quot; name=&quot;happy&quot; onclick=&quot;getElementName()&quot; value=&quot;click &quot;&gt;&lt;input type=&quot;button&quot; name=&quot;happy&quot; onclick=&quot;getElementName()&quot; value=&quot;click &quot;&gt; </p><p style="text-indent: 2em">&lt;/form&gt; </p><p style="text-indent: 2em">&lt;/body&gt; </p><p style="text-indent: 2em">&lt;/html&gt; </p><p style="text-indent: 2em">　　document.getElementsByName()这个方法.它对一个和多个的处理是一样的,我们可以用:</p><p style="text-indent: 2em">　　Temp = document.getElementsByName('happy')来引用</p><p style="text-indent: 2em">　　当Temp只有1个的时候,那么就是Temp[0],有多个的时候,用下标法Temp[i]循环获取</p><p style="text-indent: 2em">　　也有例外:</p><p style="text-indent: 2em">　　在ie 中getElementsByName(&ldquo;test&ldquo;)的时候返回的是id=test的object数组，而Firefox则返回的是name= test的object的数组。</p><p style="text-indent: 2em">　　按照w3c的规范应该是返回的是name= test的object的数组。</p><p style="text-indent: 2em">　　firefox和ie中的getElementByID相同:获取对 ID 标签属性为指定值的第一个对象的引用。</p><p style="text-indent: 2em">　　注意getElementsByName 有s在里面</p><p style="text-indent: 2em">　　document.getElementById()可以控制某个id的tag</p><p style="text-indent: 2em">　　document.getElementsByName()，返回的是一个具有相同 name 属性的元素的集合，而不是某个，注意有&ldquo;s&rdquo;。</p><p style="text-indent: 2em">　　而 document.getElementsByTagName() 返回的是一组相同 TAG 的元素集合。</p><p style="text-indent: 2em">　同一个name可以有多个element，所以用document.getElementsByName(&quot;theName&quot;) </p><p></p><p>　　他return 一个collection，引用的时候要指名index</p><p>　　var test = document.getElementsByName('testButton')[0];</p><p>　　id那个，是唯一的</p><p>　　还应该注意:对类似没有name属性，对它name属性为伪属性document.getElementsByName() 会失效，当然TD可以设置ID属性，然后用 document.getElementsByID(&quot;DDE_NODAY&quot;); 调用.</p></li><br/>Tags - <a href="tag.php?tag=javascript" rel="tag">javascript</a>
]]>
</description>
</item><item>
<link>http://www.bizeway.net/read.php?&amp;guid=0#topreply</link>
<title><![CDATA[[评论] getElementById getElementsByName getElementsByTagName]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.bizeway.net/read.php?&amp;guid=0#topreply</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>