SoFunction
Updated on 2025-04-12

The solution to getElementsByName in IE is invalid for some elements

Copy the codeThe code is as follows:

('someName') Returns a list of nodes (array)

Note: In IE, some nodes do not have the name attribute, but they cannot be obtained. Only the following tags have 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.

Alternatives:

Prerequisite: Assume that the TagName of the retrieved node array is consistent. (It is generally rare to see the nodes in the acquired node array 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 = ('span');
for(var i = 0; i &lt;  ; i++) {
if(tbcList[i].name != 'tbc' ) continue;
//...Logical code} 
......