仅限10次使用提示页面
<h1>欢迎进入本页面</h1>

<p id="countdown"></p>

<script>
    // 设置初始值为10
    let count = 10;

    // 检查是否已经使用过10次
    if (localStorage.getItem("count") !== null) {
        count = parseInt(localStorage.getItem("count"));
    }

    // 显示剩余次数
    document.getElementById("countdown").innerHTML = "您还有 " + count + " 次机会使用这个页面。";

    // 当页面关闭时,更新剩余次数
    window.addEventListener("beforeunload", function(event) {
        // 判断用户是否是主动关闭页面
        if (event.clientY < 0) {
            return; // 用户主动关闭页面,不进行计数
        }
        count--;
        localStorage.setItem("count", count);
    });

    // 如果剩余次数为0,弹出提示并禁用页面
    if (count === 0) {
        alert("您已经使用完这个页面的所有次数了!");
        document.body.innerHTML = "<h1>对不起,您没有使用这个页面的权限!</h1>";
        localStorage.removeItem("count"); // 清除计数器
    }
</script>
添加utf-8的编码!DOCTYPE htmlhtmlhead title仅限10次使用提示页面titleheadbody h1欢迎进入本页面h1 p id=countdownp script 设置初始值为10 let count = 10; 检查是否已经使用过10次 if localStoragegetI

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

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