使元素“已知”在赋值之前对 JavaScript 中的函数进行赋值

发布于 2024-11-15 21:38:55 字数 151 浏览 4 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

慕烟庭风 2024-11-22 21:38:55
window.onload = function() {

};

确保在窗口完全加载后运行代码。

window.onload = function() {

};

Make sure you run your code when the window has completely loaded.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文