我試圖擴展所有DOM元素,所以我可以得到並刪除他們的孩子。該功能如下(適用於FF和Chrome)。在IE7中是否有擴展基本dom對象的等價物?IE7中的Element.prototype?
if (!Element.get) {
Element.prototype.get = function(id) {
for (var i = 0; i < this.childNodes.length; i++) {
if (this.childNodes[i].id == id) {
return this.childNodes[i];
}
if (this.childNodes[i].childNodes.length) {
var ret = this.childNodes[i].get(id);
if (ret != null) {
return ret;
}
}
}
return null;
}
}
Element.prototype.removeChildren = function() {
removeChildren(this);
}
謝謝!
欺騙http://stackoverflow.com/questions/592815/is-there-really-no-way-to-expose-the-prototype-of-a-html-element-in-ie-8/ – bobince 2009-02-28 01:53:29