使元素“已知”在赋值之前对 JavaScript 中的函数进行赋值
我正在使用 JavaScript 编写一个页面,我有 4 个 div,所有这些都来自同一个类。每个 div 都有一个更改其他 div 样式的函数(例如边框颜色和背景颜色)。问题是最后一个 div 不会受到它上面的 div 的功能的影响,因为它还没有“分配”。有什么办法可以解决这个问题吗?
I am writing a page using JavaScript, and I have 4 divs, all of which are from the same class. Each div has a function that changes the styles of the other divs (border colour and background colour, for example). The problem is that the last div does not get affected by the functions of the divs above it, because it was not "assigned" yet. Is there any way to fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确保在窗口完全加载后运行代码。
Make sure you run your code when the window has completely loaded.