企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
## 使用js实现倒计时效果 ``` <div> <h2>恭喜您,支付成功</h2> <span id="jumpTo">10</span>秒后自动返回首页 <p><button>立即返回</button></p> </div> <script> // 逻辑:加载页面时,应该触发定时器 10s window.onload = function(){ let timer = 10; setInterval(()=>{ timer--; document.getElementById('jumpTo').innerText = timer; //时间结束后跳转 if(timer==0){ location.href = 'https://jinwen01.ke.qq.com'; } },1000); } //点击直接跳转 document.getElementsByTagName('button')[0].onclick = function(){ location.href = 'https://jinwen01.ke.qq.com'; } </script> <style> div{ margin:0 auto; width: 500px; } #jumpTo{ color: red; font-size: 30px; } </style> ``` 效果图: ![](https://img.kancloud.cn/b0/6f/b06f5ce41d2f30fec7dfff814b4d8220_356x197.png)