element.children這個擷取節點子節點的方法支援ie9及以上版本,為了能夠相容低版本的ie,可參考一下的代碼實作相容,具體的參考資料是MDN上的實作方法:
// Overwrites native 'children' prototype.
// Adds Document & DocumentFragment support for IE9 & Safari.
// Returns array instead of HTMLCollection.
(function(constructor) {
if (constructor &&
constructor.prototype &&
constructor.prototype.children == null) {
Object.defineProperty(constructor.prototype, 'children', {
get: function() {
var i = , node, nodes = this.childNodes, children = [];
while (node = nodes[i++]) {
if (node.nodeType === ) {
children.push(node);
}
}
return children;
}
});
}
})(window.Node || window.Element);