网页加载完成后再执行代码

Posted themost

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了网页加载完成后再执行代码相关的知识,希望对你有一定的参考价值。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Planets</title>
    <script>
        //网页加载完成后再执行代码
        function init (){
            var planet = document.getElementById("greenplanet");
            planet.innerHTML = "Red alert: hit by phase fire!";
        }
        window.onload = init;

    </script>
</head>
<body>
    <h1>Green Planet</h1>
    <p id="greenplanet">All is well</p>
    <h1>Red planet</h1>
    <p id="redplanet">Nothing to report</p>
    <h1>Blue planet</h1>
    <p id="blueplanet">All system A-OK</p>
</body>
</html>

 

以上是关于网页加载完成后再执行代码的主要内容,如果未能解决你的问题,请参考以下文章

JavaScript--JQuery事件 &当网页元素加载完成后再去执行事件

js中,如何等待多个图片加载完后再执行其他的js代码。

jQuery文档就绪

js等待图片加载完毕后再显示

在页面加载的时候就想要执行某个JS操作而不是在页面加载完后再执行该怎么做

NodeJS - 等到流式传输多个文件完成后再继续编写代码