Home  >  Article  >  Web Front-end  >  JS.findElementById() usage introduction_javascript skills

JS.findElementById() usage introduction_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:22:062068browse
Copy code The code is as follows:

his.findElementById = function (identifier, frame) {
if (!frame) {
frame = window;
}

var element = frame.document.getElementById(identifier);
if (element && element.getAttribute('id') = == identifier) ​​{
return element;
}
// else if (browserVersion.isIE || browserVersion.isOpera) {
// // SEL-484
// var xpath = '/descendant::*[@id=' identifier.quoteForXPath() ']';
// return this
// .findElementByXPath(xpath);
// }
else {
// MOD 2011-12-9 Some new windows have the same frame as the old window. Generally, the new window is operated first. Find from back to front
if (frame.frames && frame.frames.length > 0) {
for (var i = frame.frames.length - 1; i >= 0; i--) {
element = this.findElementById(identifier, frame.frames[i]); //frames[i].document.getElementById(identifier);
if (element && element.getAttribute("id") = == identifier) ​​{
return element;
}
}
}
}
return null;
};
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