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
Release: 2016-05-16 16:35:03
Original
1324 people have browsed it

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>
......

Copy after login

javascript code snippet:

...... 
var tbcList = document.getElementsByTagName('span');
for(var i = 0; i < tbcList.length ; i++) {
if(tbcList[i].name != 'tbc' ) continue;
//......逻辑代码
} 
......
Copy after login
Related labels:
ie
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template