GetElementsByName of solution in IE that is not valid for some elements

  • 2020-03-30 04:00:49
  • OfStack

document.getElementsByName('someName') Returns a list of nodes (array)

Note: some nodes under the IE is no name attribute, is to use the document. The getElementsByName can't get. Only the following tag has 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, div, span, etc


Premise: assume that the TagName of the acquired array of nodes is the same. (it is also rare that the nodes in the acquired node array are 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>

Javascript snippet:

var tbcList = document.getElementsByTagName('span');
for(var i = 0; i < tbcList.length ; i++) {
if(tbcList[i].name != 'tbc' ) continue;
//. Logic code

Related articles: