我正在尝试垫片Element.prototype.children http://www.w3.org/TR/domcore/#dom-element-children应该返回一个HTML集合 http://www.w3.org/TR/domcore/#htmlcollection
有一个window.HTMLCollection https://developer.mozilla.org/en/DOM/HTMLCollection
However
var h = new HTMLCollection();
//TypeErrror: HTMLCollection is not a constructor
and
var h = Object.create(HTMLCollection.prototype);
h[0] = div;
h.item(0);
// Could not convert JavaScript argument
测试 Firefox 7 和 Chrome
除了垫片之外HTMLCollection
有什么办法可以与之互动吗?
还提供反馈这个 github 问题 https://github.com/Raynos/DOM-shim/issues/5如果你能提出一个解决方案
我认为这是创建 HTMLCollection 的正确方法,由浏览器处理。
var docFragment = document.createDocumentFragment();
docFragment.appendChild(node1);
docFragment.appendChild(node2);
var myHTMLCollection = docFragment.children;
Refs.:
https://stackoverflow.com/a/35969890/10018427 https://stackoverflow.com/a/35969890/10018427
https://developer.mozilla.org/en-US/docs/Web/API/NodeList https://developer.mozilla.org/en-US/docs/Web/API/NodeList
https://developer.mozilla.org/en-US/docs/Web/API/HTMLCollection https://developer.mozilla.org/en-US/docs/Web/API/HTMLCollection
https://www.w3schools.com/js/js_htmldom_nodelist.asp https://www.w3schools.com/js/js_htmldom_nodelist.asp
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)