Home >Web Front-end >JS Tutorial >Solution to why getElementsByName() in IE is invalid for some elements_javascript skills

Solution to why getElementsByName() in IE is invalid for some elements_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:35:031298browse

Copy code The code is as follows:

document.getElementsByName('someName') returns a node list (array)

Note: Some nodes do not have a name attribute under IE, which cannot be obtained using document.getElementsByName. Only the following tags have the name attribute:
A, APPLET, attribute, BUTTON, EMBED, FORM, IMG, INPUT type=button, INPUT type=checkbox, INPUT type=file, INPUT type=hidden, INPUT type=image, INPUT type=password, INPUT type=radio, INPUT type=reset, INPUT type=submit, INPUT type=text, LINK, MAP, OBJECT, RT, RUBY, SELECT, TEXTAREA

Nothing else, such as div, span, etc.

Alternative:

Prerequisite: It is assumed that the TagNames of the obtained node arrays are consistent. (It is generally rare that the nodes in the obtained node array come from different tags)

JSP code snippet:

......
<logic:iterate id='t' name='dataList' >
<tr class='list'> 
......
<td class='normal'><span name='tbc'>${t.LOWAREATS_TBC }</span></td>
......
</tr>
</logic:iterate>
......

javascript code snippet:

...... 
var tbcList = document.getElementsByTagName('span');
for(var i = 0; i < tbcList.length ; i++) {
if(tbcList[i].name != 'tbc' ) continue;
//......逻辑代码
} 
......
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn