本文实例讲述了php实现通用alert函数的方法。分享给大家供大家参考。具体如下:
函数:通用提示
参数:提示訊息,類型或網址,窗口名或函數名,延时毫秒
alert("","function","close2",300);
代码如下:
function alert($str,$typ="back",$topwindow="",$tim=100){
echo "
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('return {$topwindow}')();_t();".chr(10);
break;
//die();
default:
if($typ!=""){
//echo "window.{$winname}.location.href='{$typ}';";
echo "window.{$winname}.location=('{$typ}');";
}
}
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 "".chr(10);
exit();
}
希望本文所述对大家的php程序设计有所帮助。
如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!