這是一個通過js實作的支付后的頁面,點擊支付會跳出一個彈窗,提示你是否要確定支付,確定后進入付后界面,該頁面有著10秒倒計時,計時結束后便會回傳原界面,也可以選擇立刻回傳,來回傳主頁面
第一個zhifu.html頁面
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>支付頁面</title> <style> div { width: 200px; height: 280px; background-color: #eee; padding: 20px; margin: auto; } button { margin: 30px 25px; } </style> </head> <body> <div> <p>商品:web前端課程</p> <p>原價:1980元</p> <p>現價:1.98元</p> <p>內容:html、css、JavaScript</p> <p>地址:鄭州升達經貿管理學院</p> <p> <button>取消</button> <button>支付</button> </p> </div> <script> //點擊支付出現確認框 document.getElementsByTagName('button')[1].onclick = function() { let res = window.confirm('您確認要支付嗎?') if (res) { location.href = 'https://www.cnblogs.com/Ldz123/p/ten.html' } } </script> </body> </html>
第二個ten.html頁面
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>10秒倒計時</title>
<style>
div {
margin: 0 auto;
width: 500px;
}
#jumpto {
color: red;
font-size: 30px;
}
</style>
</head>
<body>
<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').innerHTML = timer;
if (timer == 0) {
location.href = 'https://www.cnblogs.com/Ldz123/p/zhifu.html';
}
}, 1000);
}
document.getElementsByTagName('button')[0].onclick = function() {
location.href = 'https://www.cnblogs.com/Ldz123/p/zhifu.html';
}
</script>
</body>
</html>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/548746.html
標籤:JavaScript
