本节内容:
getElementsByName获得span标签
1,在Firefox下通过name属性获取span标签:
复制代码 代码示例:
<span name="a">ddd</span>
<span name="a">eee</span>
<span name="a">ggg</span>
<mce:script type="text/
javascript"><!--
var obj=document.getElementsByName("a");
alert(obj.length);
// --></mce:script>
2,不过,在IE下运行会发现得到的元素个数为0,获取不到,
IE下修改为如下:
复制代码 代码示例:
<span id="a">ddd</span>
<span id="a">eee</span>
<span id="a">ggg</span>
<mce:script type="text/javascript"><!--
var obj=document.getElementsByName("a");
alert(obj.length);
// --></mce:script>