不。
......但是你可以:
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/