没有。
...但是你可以,但:
Element.prototype.getElementById = function(id) {
return document.getElementById(id);
}
试试这个页面上:
var x = document.getElementById('footer').getElementById('copyright');
编辑:Pumbaa80指出的那样,你想别的东西。那么,就在这里。谨慎使用。
Element.prototype.getElementById = function(req) {
var elem = this, children = elem.childNodes, i, len, id;
for (i = 0, len = children.length; i < len; i++) {
elem = children[i];
//we only want real elements
if (elem.nodeType !== 1)
continue;
id = elem.id || elem.getAttribute('id');
if (id === req) {
return elem;
}
//recursion ftw
//find the correct element (or nothing) within the child node
id = elem.getElementById(req);
if (id)
return id;
}
//no match found, return null
return null;
}
一个例子:http://jsfiddle.net/3xTcX/
考虑[jQuery](http://jquery.com/)。 – 2011-04-15 22:53:04
或[MooTools](http://mootools.net/)(它扩展了'DOMElement'对象以支持'getElementById'方法)。 – 2011-04-15 22:54:08