简体   繁体   English

HTMLCollection将记录到控制台,但是记录.count返回未定义?

[英]HTMLCollection will log to console, but logging .count returns undefined?

What's the deal? 这是怎么回事?

var blocks = document.getElementsByClassName('code-block');

Just grabbing all my textareas. 只是抓住我所有的文本区域。

console.log(blocks);

returns a HTMLCollection with all 14 items. 返回具有所有14个项目的HTMLCollection。

console.log(blocks.count);

returns 退货

undefined

I did try setTimeout but that didn't help. 我确实尝试过setTimeout,但没有帮助。 I'm also inside a document.ready function and in the global scope. 我也在document.ready函数内部并且在全局范围内。 If it makes a difference, all my textareas are inside of a .collapsible div from Materialize.css so they are not initially visible. 如果有所不同,我的所有文本区域都位于Materialize.css的.collapsible div内,因此最初不可见。

blocks.length 

哇,这是我最近一直在与Swift一起工作的原因。哈哈。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM