PHP页面提示与跳转,ThinkPHP默认提示跳转函数
这是一个ThinkPHP默认的跳转效果,觉得还不错,可能在一些项目的过程中,为了比较友好的用户体验,有可能会使用得到。所以我将其写成函数的形式,方便用于调用。可以在不是框架的结构上使用。
函数
/** * [message 跳转类型] * @param [type] $type [成功success,失败error] * @param [type] $message [提示语,操作成功。操作失败] * @param [type] $jumpUrl [跳转URL地址] * @param integer $time [跳转停顿时间] * @author [建百站www.jianbaizhan.com] */ function message($type = 'success',$message = '',$jumpUrl,$time = 3){ $str = '<!DOCTYPE HTML><html><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>跳转提示</title> <style type="text/css"> *{ padding: 0; margin: 0; } body{ background: #fff; font-family: \'微软雅黑\'; color: #333; font-size: 16px; } .system-message{ padding: 24px 48px; } .system-message h1{ font-size: 100px; font-weight: normal; line-height: 120px; margin-bottom: 12px; } .system-message .jump{ padding-top: 10px} .system-message .jump a{ color: #333;} .system-message .success,.system-message .error{ line-height: 1.8em; font-size: 36px } .system-message .detail{ font-size: 12px; line-height: 20px; margin-top: 12px; display:none} </style> </head> <body> <div class="system-message">'; if($type == 'success'){ $str .= '<h1>:)</h1> <p class="success">'.$message.'</p>'; }elseif($type == 'error'){ $str .= '<h1>:(</h1> <p class="error">'.$message.'</p>'; }else{ //TO DO } $str .= '<p class="detail"></p> <p class="jump"> 页面自动 <a id="href" href="'.$jumpUrl.'">跳转</a> 等待时间: <b id="wait">'.$time.'</b> </p> </div> <script type="text/javascript"> (function(){ var wait = document.getElementById(\'wait\'),href = document.getElementById(\'href\').href; var interval = setInterval(function(){ var time = --wait.innerHTML; if(time <= 0) { location.href = href; clearInterval(interval); }; }, 1000); })(); </script> </body> </html>'; echo $str; exit; }
使用方法
message('success','操作成功!','http://www.jianbaizhan.com/',2); // message('error','操作失败!','http://www.jianbaizhan.com/',5);
本文作者: Liaodeity
本文链接: https://www.jianbaizhan.com/article/242.html
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 3.0 许可协议。转载请注明出处!