javascript - 即使有元素也无法访问 HTMLCollection
问题描述
当条件满足时,我会尝试更改一些元素。我需要xTick[0]
,但即使有 HTMLColletion 它总是未定义
var xTick = document.getElementsByClassName('some class name')
控制台日志
console.log(xTick)
output:
HTMLCollection []
> 0: text
> 1: text
> 2: text
...
> 8: text
> 9: text
length: 10
> __proto__: HTMLCollection
console.log(xTick.length)
output: 0
console.log(xTick[0])
output: undefined
console.log(xTick)
有正确的输出console.log(xTick[0])
但console.log(xTick.length)
没有
解决方案
推荐阅读
- common-lisp - 更正正则表达式“\[([a-zA-Z0-9_-]+)]”
- postgresql - 如何以零停机时间向生产 PostgreSQL 的表中添加列?
- spring-boot - 如何使用 thymeleaf + Spring boot 动态解析 html 模板?
- game-maker - Issue with game over room
- python-3.x - 如何正确处理 Wagtail 大文件上传
- angular - 调用服务绑定组件中指令属性的常用函数
- html - 为什么我的一些(不是全部)样式不能在移动设备上运行
- python-3.x - 在 selenium/web 驱动程序单击选项后将文件保存到 s3 位置
- python - 如何在这个while循环中放置多个操作?
- python - UnsupportedOperation:不能进行非零末端相对搜索:Python - PyPDF2