Javascript .clientwidth在Chrome中返回0

Javascript .clientwidth在Chrome中返回0,javascript,html,Javascript,Html,有人能指出为什么在Chrome浏览器中,.clientWidth返回0,在Firefox中运行良好吗 这是我的密码: const sliderRowItems = document.querySelectorAll(".slider-row img"); const size = sliderRowItems[0].clientWidth; 在您的中,您试图从文档中访问已经收集的节点列表,就好像它是它的属性一样: const sliderRowItems = document.queryS

有人能指出为什么在Chrome浏览器中,
.clientWidth
返回0,在Firefox中运行良好吗

这是我的密码:

const sliderRowItems = document.querySelectorAll(".slider-row img");
const size = sliderRowItems[0].clientWidth;

在您的中,您试图从
文档中访问已经收集的
节点列表
,就好像它是它的属性一样:

const sliderRowItems = document.querySelectorAll(".slider-row img");
let doc = document;

// that's the line causing problems, it even errors out in the console
const size = doc.sliderRowItems[0].clientWidth;

只需从该行中删除
doc.

类似:,您能否复制该问题?。因为它对我来说工作正常。请检查chrome版本,
43
以上版本的chrome支持
clientWidth
。我的版本是80。当我尝试单独使用它时,它对我也很好。这就是我的全部。我想问题出在哪里了。
const sliderRowItems = document.querySelectorAll(".slider-row img");
let doc = document;

// that's the line causing problems, it even errors out in the console
const size = doc.sliderRowItems[0].clientWidth;