要实现5秒倒计时后跳转到官网首页,可以使用JavaScript的定时器函数setTimeout。

在<script>标签中添加以下代码:

setTimeout(function() {
    var timeElement = document.getElementById("time");
    var timeLeft = parseInt(timeElement.textContent);

    if (timeLeft > 1) {
        timeElement.textContent = timeLeft - 1;
        setTimeout(arguments.callee, 1000);
    } else {
        window.location.href = "https://www.example.com"; // 替换为官网首页的链接
    }
}, 1000);

这段代码将会在页面加载后立即执行。首先,它获取id为time的span元素,并将其内容解析为整数。然后,它检查剩余的时间是否大于1秒。如果是,将剩余时间减1,并使用setTimeout函数再次调用自身,延迟1秒执行。如果剩余时间小于等于1秒,则会使用window.location.href将页面重定向到官网首页的链接。

请将代码中的 "https://www.example.com" 替换为你想要跳转到的官网首页的链接

HTML!DOCTYPE htmlhtml lang=enhead meta charset=UTF-8 meta http-equiv=X-UA-Compatible content=IE=edge meta name=viewport content=width=device-width initial-scale=10 title作业2titleheadbody

原文地址: http://www.cveoy.top/t/topic/iPh9 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录