«
封装常用Javascript以便PHP快速调用

时间:2008-5-31    作者:Deri    分类: 分享


   <p>  <code><?php<br />//<br />// +----------------------------------------------------------------------+<br />// | JS    javascript 类                       |<br />// +----------------------------------------------------------------------+<br />// | Copyright (c) 2001 NetFish Software                 |<br />// |                                   |<br />// | Author: whxbb(whxbb@21cn.com)                    |<br />// +----------------------------------------------------------------------+<br />//<br />// $Id: js.class.php,v 0.1 2001/8/5 18:48:33 yf Exp $<br />//<br />// 禁止直接访问该页面<br />if (basename($HTTP_SERVER_VARS['PHP_SELF']) == "js.class.php") {<br />  header("HTTP/1.0 404 Not Found");<br />}<br />/**<br />* Purpose<br />* 封装了一些常用的Javascript代码,以便在PHP中快速调用<br />* @author : whxbb(whxbb@21cn.com)<br />* @version : 0.1<br />* @date  : 2001/8/5<br />*/<br />class JS<br />{<br />  function JS(){}<br /> &#160;<br />  /**<br />  &#160;* 返回上页<br />  &#160;* @param $step 返回的层数 默认为1<br />  &#160;*/<br />  function Back($step = -1)<br />  {<br />    $msg = "history.go(".$step.");";<br />    JS::_Write($msg);<br />    JS::FreeResource();<br />    exit;<br />  }<br />  /**<br />  &#160;* 弹出警告的窗口<br />  &#160;* @param $msg 警告信息<br />  &#160;*/<br />  function Alert($msg)<br />  {<br />    $msg = "alert(\"".$msg."\");";<br />    JS::_Write($msg);<br />  }<br />  /**<br />  &#160;* 写js<br />  &#160;* @param $msg<br />  &#160;*/<br />  function _Write($msg)<br />  {<br />    echo "<script language=\"javascript\">\n";<br />    echo $msg;<br />    echo "\n</script>";<br />  }<br />  /**<br />  &#160;* 刷新当前页<br />  &#160;*/<br />  function Reload()<br />  {<br />    $msg = "location.reload();";<br />    JS::FreeResource();<br />    JS::_Write($msg);<br />    exit;<br />  }<br />  /**<br />  &#160;* 刷新弹出父页<br />  &#160;*/<br />  function ReloadOpener()<br />  {<br />    $msg = "if (opener)  opener.location.reload();";<br />    JS::_Write($msg);<br />  }<br />  /**<br />  &#160;* 跳转到url<br />  &#160;* @param $url 目标页<br />  &#160;*/<br />  function Goto($url)<br />  {<br />    $msg = "location.href = '$url';";<br />    JS::FreeResource();<br />    JS::_Write($msg);<br />    exit;<br />  }<br />  /**<br />  &#160;* 关闭窗口<br />  &#160;*/<br />  &#160;function Close()<br />  &#160;{<br />    &#160;$msg = "window.close()";<br />    JS::FreeResource();<br />    JS::_Write($msg);<br />    exit;<br />   &#160;<br />  &#160;}<br />  /**<br />  &#160;* 提交表单<br />  &#160;* @param $frm 表单名<br />  &#160;*/<br />  function Submit($frm)<br />  {<br />    $msg = $frm.".submit();";<br />    JS::_Write($msg);<br />  }<br />  /**<br />  &#160;* 关闭数据库连接<br />  &#160;*/<br />  function FreeResource()<br />  {<br />    // 数据库连接标志<br />    global $conn;<br />    if (is_resource($conn))<br />      @mysql_close($conn);<br />  }<br />}<br />?><br /></code></p>