Home  >  Article  >  Web Front-end  >  How to adapt getElementsByName to IE and firefox_javascript skills

How to adapt getElementsByName to IE and firefox_javascript skills

WBOY
WBOYOriginal
2016-05-16 19:08:581282browse

In the w3c specification, getElementsByName is retrieved by the name attribute, but MS's IE is retrieved by the id. As a result, we cannot get the Elements we should get. To adapt to the browser, we can make some adjustments:
1. Add id to the names that need to use getElementsByName, and the id and name are the same.
2. Use a function to adapt to the browser. The code is as follows:

Copy the code The code is as follows:

getElementsByName:function (name) {
var returns = document.getElementsByName(name);
if(returns.length > 0) return returns;
returns = new Array();
var e = document.getElementsByTagName('td');
for(i = 0; i < e.length; i ) {
if(e[i].getAttribute("name") = = name) {
                                                                                                                                    
}

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