setAttribute不确定,为什么?
这是我的代码:
[在html]````
``` [in css]``` .myclass { width:50%; }```[在JS] function candlyWidth(){让mynodes = document.getElementsByClassName('。myClass')); mynodes.setAttribute('width','100%'); }
然后,运行此功能时,它显示: Unturect TypeError:无法阅读未定义的属性,当阅读“ setAttribute”时
会发生什么以及如何纠正? 谢谢
This is my code follow:
[in html]```
```
[in css]```
.myclass {
width:50%;
}```
[in js]function changewidth() { let mynodes = document.getElementsByClassName('.myclass'); mynodes.setAttribute('width','100%'); }
then, when this function be run, it display:
Uncaught TypeError: Cannot read properties of undefined, when reading 'setAttribute'
what happen and how to correct ?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该错误说mynodes变量是未定义的,含义JavaScript无法在任何地方找到它,因为它不存在。
删除其中的点(。)
应该是
The error says that the myNodes variable is undefined meaning JavaScript cant find it anywhere because it doesn't exist.
Remove the dot(.) in
It should be