Home > Backend Development > PHP Tutorial > How to implement prompt information using PHP's custom alert function

How to implement prompt information using PHP's custom alert function

墨辰丷
Release: 2023-03-31 20:20:01
Original
2149 people have browsed it

这篇文章主要介绍了PHP实现通用alert函数的方法,实例分析了php自定义alert函数实现提示信息的技巧,非常具有实用价值,需要的朋友可以参考下

本文实例讲述了PHP实现通用alert函数的方法。具体如下:

函数:通用提示
参数:提示訊息,類型或網址,窗口名或函數名,延时毫秒
Alert("","function","close2",300);

代码如下:

function Alert($Str,$Typ="back",$TopWindow="",$Tim=100){
  echo "<script>".chr(10);
  if(!empty($Str)){
    echo "alert(\"Warning:\\n\\n{$Str}\\n\\n\");".chr(10);
  }
  echo "function _r_r_(){";
  $WinName=(!empty($TopWindow))?"top":"self";
  switch (StrToLower($Typ)){
  case "#":
    break;
  case "back":
    echo $WinName.".history.go(-1);".chr(10);
    break;
  case "reload":
    echo $WinName.".window.location.reload();".chr(10);
    break;
  case "close":
    echo "window.opener=null;window.close();".chr(10);
    break;
  case "function":
    echo "var _T=new function(&#39;return {$TopWindow}&#39;)();_T();".chr(10);
    break;
    //Die();
  Default:
    if($Typ!=""){
      //echo "window.{$WinName}.location.href=&#39;{$Typ}&#39;;";
      echo "window.{$WinName}.location=(&#39;{$Typ}&#39;);";
    }
  }
  echo "}".chr(10);
  //為防止Firefox不執行setTimeout
  echo "if(setTimeout(\"_r_r_()\",".$Tim.")==2){_r_r_();}";
  if($Tim==100){
    echo "_r_r_();".chr(10);
  }else{
    echo "setTimeout(\"_r_r_()\",".$Tim.");".chr(10);
  }
  echo "</script>".chr(10);
  Exit();
}
Copy after login

总结:以上就是本篇文的全部内容,希望能对大家的学习有所帮助。

相关推荐:

PHP 错误及异常处理

PHP实例分析了mysql事务处理的使用技巧

16个常见的php基本函数

The above is the detailed content of How to implement prompt information using PHP's custom alert function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template