PHP 如何实现提示后跳转?-PHP问题

资源魔 35 0

PHP 若何完成提醒后跳转?

起首创立一个PHP文件,并关上编纂;

而后正在PHP代码顶用函数“echo()”输入JS代码;

接着正在JS代码中应用函数“alert()”提醒音讯;

最初将JS中“location.href”指向跳转链接便可。

代码示例

function show_msg($msg, $url)
{
    echo "<script>alert('{$msg}');window.location.href='{$url}';</script>";
    exit();
}

show_msg('this is Message!', '/user/show');

进阶版

function message($msgTitle,$message,$jumpUrl){ 
    $str = '<!DOCTYPE HTML>'; 
    $str .= '<html>'; 
    $str .= '<head>'; 
    $str .= '<meta charset="utf-8">'; 
    $str .= '<title>页面提醒</title>'; 
    $str .= '<style type="text/css">'; 
    $str .= '*{margin:0; padding:0}a{color:#369; text-decoration:none;}a:hover{text-decoration:underline}body{height:100%; font:12px/18px Tahoma, Arial,  sans-serif; color:#424242; background:#fff}.message{width:450px; height:120px; margin:16% auto; border:1px solid #99b1c4; background:#ecf7fb}.message h3{height:28px; line-height:28px; background:#2c91c6; text-align:center; color:#fff; font-size:14px}.msg_txt{padding:10px; margin-top:8px}.msg_txt h4{line-height:26px; font-size:14px}.msg_txt h4.red{color:#f30}.msg_txt p{line-height:22px}'; 
    $str .= '</style>'; 
    $str .= '</head>'; 
    $str .= '<body>'; 
    $str .= '<div class="message">'; 
    $str .= '<h3>'.$msgTitle.'</h3>'; 
    $str .= '<div class="msg_txt">'; 
    $str .= '<h4 class="red">'.$message.'</h4>'; 
    $str .= '<p>零碎将正在 <span style="color:blue;font-weight:bold">3</span> 秒后主动跳转,假如没有想期待,间接点击 <a href="{$jumpUrl}">这里</a> 跳转</p>'; 
    $str .= "<script>setTimeout('location.replace('".$jumpUrl."')',2000)</script>"; 
    $str .= '</div>'; 
    $str .= '</div>'; 
    $str .= '</body>'; 
    $str .= '</html>'; 
    echo $str; 
}

保举教程:《PHP》

以上就是PHP 若何完成提醒后跳转?的具体内容,更多请存眷资源魔其它相干文章!

标签: php php教程 跳转 php故障解决 php使用问题

抱歉,评论功能暂时关闭!