网站推广.NET

网站推广.NET

php中alert函数的用法

来源:互联网

php实现通用alert函数的方法。分享给大家供大家参考。具体如下:

函数:通用提示 (推荐学习:PHP视频教程)

参数:提示信息,类型或网址,窗口名或函数名,延时毫秒

Alert("","function","close2",300);

代码如下:

立即学习“PHP免费学习笔记(深入)”;

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();}
alert用法