常用JS Claass

<?php
/**
 * JS class.
 *
 * BugFree is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * BugFree is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with BugFree; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * @link        http://www.okooo.com/OpenSource/
 * @copyright   Copyright: 2004-2004 Beijing SeaSun Media and Technology Co. Ltd.
 * @author      designer:  Zhenfei Liu    <liuzf@pku.org.cn> <br />
 *              developer: Chunsheng Wang <wwccss@263.net>   <br />               
 * @package     BugFree
 * @version     $Id: JS.class.php,v 1.3 2004/11/30 10:42:21 wangcs Exp $
 */
class JS
{
   /**
 * show a alert box.
 *
 * @param string $Text  the text to be showd in the alert box.
 */
 var $Charset = "UTF-8";

 function alert($Text)
 {
  echo "<HTML>/n<HEAD>/n<TITLE> New Document </TITLE>/n<meta http-equiv=/"Content-Type/"  content=/"text/html; charset={$this -> Charset}/">/n</HEAD>/n<BODY>/n";
  echo '<Script language="Javascript">alert("'.$Text.'");</Script>';
  echo "/n";
  echo "/n</body></html>";
 }
 
   /**
 * show a confirm box, press ok go to URL1, else go to URL2.
 *
 * @param string $Text   the text to be showed.
 * @param string $URL1   the url to go to when press 'ok'.
 * @param string $URL2   the url to go to when press 'cancle'.
 * @param string $Target the name of the window to change location.
 */
 function confirm($InfoText,$URL1,$URL2,$Target="self")
 {
  echo "<HTML>/n<HEAD>/n<TITLE> New Document </TITLE>/n<meta http-equiv=/"Content-Type/"  content=/"text/html; charset={$this -> Charset}/">/n</HEAD>/n<BODY>/n";
  echo '<script language="javascript">
            if (confirm("'.$InfoText.'"))
            {
               if("'.$URL1.'" == "Back")
               {
                 history.back(-1)
               }
               else
               {
                 '.$Target.'.location = "'.$URL1.'"
               }
            }
            else
            {
             if("'.$URL2.'" == "Back")
               {
                 history.back(-1)
               }
               else
               {
                 '.$Target.'.location = "'.$URL2.'"
               }
            }
          </script>';
     echo "/n</body></html>";
 }
 
   /**
 * change the location of the $Target window to the $URL.
 *
 * @param string $URL   
 * @param string $Target
 */
 function goto($URL,$Target="self")
 {
  if ($URL == "Back")
  {
   echo "<HTML>/n<HEAD>/n<TITLE> New Document </TITLE>/n<meta http-equiv=/"Content-Type/"  content=/"text/html; charset={$this -> Charset}/">/n</HEAD>/n<BODY>/n";
   echo "<Script Language=/"Javascript/">history.go(-1)</Script>";
      echo "/n</body></html>";
  }
  elseif ($URL == "Back2")
  {
   echo "<HTML>/n<HEAD>/n<TITLE> New Document </TITLE>/n<meta http-equiv=/"Content-Type/"  content=/"text/html; charset={$this -> Charset}/">/n</HEAD>/n<BODY>/n";
   echo "<Script Language=/"Javascript/">history.go(-2)</Script>";
      echo "/n</body></html>";
  }
  else
  {
   echo "<HTML>/n<HEAD>/n<TITLE> New Document </TITLE>/n<meta http-equiv=/"Content-Type/"  content=/"text/html; charset={$this -> Charset}/">/n</HEAD>/n<BODY>/n";
   echo "<Script Language=/"Javascript/">".$Target.".location=/"".$URL."/"</Script>";
      echo "/n</body></html>";
  }
 }
 
   /**
 * select an item of a select box.
 *
 * @param string $ObjName        the object name of the select box.
 * @param string $ItemValue      the value of the item to be selected.
 * @param string $FunctionName   the name of the function to create. If empty, execute directly.
 * @param booble $Echo           show directly or false.
 */
 function selectOption($ObjName,$ItemValue,$FunctionName="",$Echo=false)
 {
  $JS = "    <script language='Javascript'>";
  if(!empty($FunctionName))
        {
            $JS .= "function $FunctionName(){";
        }
        $JS .="
        var Value='".$ItemValue."';
        for(I = 0;I < ".$ObjName.".options.length; I++)
        {
            if(Value.indexOf(',') >=0)
            {
                ValueList = Value.split(',');
                for(Y = 0;Y < ValueList.length;Y++)
                {
                    if(ValueList[Y] == ".$ObjName.".options[I].value)
                    {
                        ".$ObjName.".options[I].selected = true;
                    }
                }
            }
            else if(Value == ".$ObjName.".options[I].value)
            {
               ".$ObjName.".options[I].selected = true;
            }
        }";
        if(!empty($FunctionName))
        {
            $JS .= "}";
        }
        $JS .="
        </script>
        ";
  if($Echo)
  {
      echo $JS;
  }
  return $JS;
 }
   /**
 * select an item of a group of radios.
 *
 * @param string $ObjName   the object name of the radios.
 * @param string $ItemValue the value of the item to be selected.
 * @param booble $Echo      show or false.
 */
 function selectRadio($ObjName,$ItemValue,$Echo=false)
 {
  $JS =  '<script language="javascript">';
  $JS .= '
        for(I=0;I<'.$ObjName.'.length;I++)
        {
          if('.$ObjName.'[I].value == "'.$ItemValue.'")
          {
              '.$ObjName.'[I].checked=true;
          }
        }';
     $JS .= "</script>/n";
     return $JS;
 }
 
   /**
 * close current window.
 *
 */
 function closeWindow()
 {
  echo "<HTML>/n<HEAD>/n<TITLE> New Document </TITLE>/n<meta http-equiv=/"Content-Type/"  content=/"text/html; charset={$this -> Charset}/">/n</HEAD>/n<BODY>/n";
  echo "<script language=javascript>window.close();</script>";
  echo "/n</body></html>";
 }
}
?>
<?php
/**
 * $Log: JS.class.php,v $
 * Revision 1.3  2004/11/30 10:42:21  wangcs
 *  * change the comments to english.
 *
 */
?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值