Cara melaksanakan lompatan selepas lima saat dalam PHP: 1. Buat halaman kejayaan operasi success.php 2. Buat halaman kegagalan operasi error.php 3. Laksanakan lima saat melalui "playSec(5); "Ia akan melompat selepas beberapa saat.
Persekitaran pengendalian artikel ini: sistem Windows 7, PHP versi 7.1, komputer Dell G3.
Bagaimana untuk melompat selepas lima saat dalam php?
PHP akan melompat ke halaman secara automatik selepas 5 saat:
history.go(-2);
setTimeout("playSec(" num ")",1000); //Kod JavaScript, pemasa, panggil fungsi playSec() selepas satu saat.
kejayaan.php Halaman kejayaan operasi
ralat.php Halaman kegagalan operasi
1. success.php Halaman kejayaan operasi
<?php $message=urldecode($_GET["message"]); $url=trim($_GET["url"]); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>操作成功</title> <style type="text/css"> *{margin:0px;padding:0px;} .box{ width:450px; border:1px solid #f0f0f0; background:#FFFFCC; margin:100px auto; padding:20px; font-size:14px; line-height:180%; color:#444; } h2{margin-bottom:10px;} #time{color:#FF0000;} .color2{color:#0099FF;} a.a1:link,a.a1:visited{color:#0099FF;text-decoration:none;} a.a1:hover{color:#FF0000;text-decoration:underline;} </style> </head> <body> <div class="box"> <h2 align="center">操作成功</h2> <p><b>提示:<?php echo $message;?></b></p> <p>系统将在 <span id="time">3</span> 秒钟后自动跳转,如果不想等待,请点击 <a class="a1" href="<?php echo $url?>">这里</a> 跳转。</p> </div> </body> </html> <script language="javascript"> function playSec(num) { time.innerText=num; if(--num >0) { setTimeout("playSec("+num+")",1000); //设置定时器,一秒后调用playSec()函数 }else { location.href="<?php echo $url?>"; //跳转到其他页面 } } playSec(3); </script>
2. error.php Halaman kegagalan operasi
<?php $message=urldecode($_GET["message"]); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>操作成功</title> <style type="text/css"> *{margin:0px;padding:0px;} .box{ width:450px; border:1px solid #f0f0f0; background:#FFFFCC; margin:100px auto; padding:20px; font-size:14px; line-height:180%; color:#444; } h2{margin-bottom:10px;} #time{color:#FF0000;} .color2{color:#0099FF;} a.a1:link,a.a1:visited{color:#0099FF;text-decoration:none;} a.a1:hover{color:#FF0000;text-decoration:underline;} </style> </head> <body> <div class="box"> <h2 align="center">操作失败</h2> <p><b>提示:<?php echo $message;?></b></p> <p>系统将在 <span id="time">5</span> 秒钟后自动跳转,如果不想等待,请点击 <a class="a1" href="javascript:history.go(-2);">这里</a> 跳转。</p> </div> </body> </html> <script language="javascript"> function playSec(num) { var time = document.getElementById("time"); time.innerText=num; if(--num >0) { setTimeout("playSec("+num+")",1000); //设置定时器,每一秒调用一次playSec()函数 }else { history.go(-2); //后退两个页面 } } playSec(5); </script>
Pembelajaran yang disyorkan: "Tutorial Video PHP"
Atas ialah kandungan terperinci Bagaimana untuk melompat selepas lima saat dalam php. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!