0
無法獲得的childNodes computedStyle,得到一個錯誤:無法獲得的childNodes computedStyle
Uncaught TypeError: Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'
let wrappers = document.querySelectorAll('[data-attribute="wrapper"]');
wrappers = Array.prototype.slice.call(wrappers);
wrappers.forEach((el) => {
let wrappersChildren = wrappers.slice.call(el.childNodes, 0);
wrappersChildren.forEach((el) => {
const childrenWidth = window.getComputedStyle(el).width;
...
如果我沒有搞錯?
但el.children只返回直接子對象,不是所有的嵌套元素。不是嗎? –
@VladimirHumeniuk,childNodes和孩子都是直系孩子,他們不包含嵌套元素/文本節點 –
@PatrickEvans所以我如何選擇所有嵌套元素? –