gpt4 book ai didi

javascript - 使用 body onload 的替代方法

转载 作者:太空狗 更新时间:2023-10-29 15:49:06 25 4
gpt4 key购买 nike

我是一个新手,我正在尝试使用 javascript 实现一些东西。

我有一个功能,我需要在我的页面加载后生效,但我不想使用 <body onload="init()"还有其他选择吗?

            <script type="text/javascript">
function init() {
container = document.createElement('div');
<script>

<body onload="init()">

</body>

最佳答案

load 处理程序中调用它:

function init() {
container = document.createElement('div');

// ...
}

window.addEventListener("load", init);

关于javascript - 使用 body onload 的替代方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33834243/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com