Home >Backend Development >PHP Tutorial >PHP 实现类似js中alert() 提示框_PHP

PHP 实现类似js中alert() 提示框_PHP

WBOY
WBOYOriginal
2016-06-01 11:06:131079browse

主要应用于添加判断提示,跳转,返回,刷新。

代码如下:


/**
 * JS提示跳转
 * @param  $tip  弹窗口提示信息(为空没有提示)
 * @param  $type 设置类型 close = 关闭 ,back=返回 ,refresh=提示重载,jump提示并跳转url
 * @param  $url  跳转url
 */
function alert($tip = "", $type = "", $url = "") {
    $js = "<script>";<br /> if ($tip)<br /> $js .= "alert('" . $tip . "');";<br /> switch ($type) {<br /> case "close" : //关闭页面<br /> $js .= "window.close();";<br /> break;<br /> case "back" : //返回<br /> $js .= "history.back(-1);";<br /> break;<br /> case "refresh" : //刷新<br /> $js .= "parent.location.reload();";<br /> break;<br /> case "top" : //框架退出<br /> if ($url)<br /> $js .= "top.location.href='" . $url . "';";<br /> break;<br /> case "jump" : //跳转<br /> if ($url)<br /> $js .= "window.location.href='" . $url . "';";<br /> break;<br /> default :<br /> break;<br /> }<br /> $js .= "</script>";
    echo $js;
    if ($type) {
        exit();
    }
}

以上所述就是本文的全部内容了,希望对大家学习php能有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn