Home  >  Article  >  Backend Development  >  php简单封装了一些常用JS操作_PHP教程

php简单封装了一些常用JS操作_PHP教程

WBOY
WBOYOriginal
2016-07-21 15:57:061056browse

在web编程中大家应该会经常用到一些常用js操作,例如 alert(),通常是遇到了再写,受公司的启发,我自己简单写了个类来自动生成这些js,目的就是为了方便,一个小玩意,新手们也许会喜欢^_^
[php]
/*
*页面:makeJs.class.php
*功能:封装常用的JS代码,直接调用,方便操作
*作者:辉老大
*创建时间:2007-01-27
*/
class makeJs
{
     private $jsStartChar = '';//定义js起始标记 
     private $jsEndChar   = '
īpt>';//定义js结束标记

/*
*函数名称:jsAlert
*函数功能:弹出JS提示框
*参数:$message 要在弹出提示框中显示的文字 $url 点击后跳转的路径,为空则不跳转
*使用方法:
*$js = new makeJs();//以下介绍使用方法省略此句
*$js->jsAlert(显示的文字,'跳转页面URL');//弹出对话框,点击确定后跳转到php.php页面
*$js->jsAlert(显示的文字,'');//弹出对话框,点击确定后没有跳转
*/
     public function jsAlert($message,$url){
        echo $this->jsStartChar;
        if($url==''){
            echo 'alert' . '("' . $message . '");';
            echo $this->jsEndChar;
        }
        else{
            echo 'alert' . '("' . $message . '");';
            echo $this->jsEndChar;
            echo '';
        }
    }

/*
*函数名称:jsConfirm
*函数功能:弹出JS提示框,带确定/取消
*参数:$message 要在弹出提示框中显示的文字
*使用方法:$js->jsConfirm('显示的文字');
*/
     public function jsConfirm($message){
        echo $this->jsStartChar;
        if($url==''){
            echo 'confirm' . '("' . $message . '");';
            echo $this->jsEndChar;
        }
     }

/*
*函数名称:jsOpenWin
*函数功能:弹出新窗口
*参数:$url 路径 $name 窗口名 $height 窗口高度 $width 窗口宽度
*使用方法:
*$url = '页面的URL';
*$js->jsOpenWin($url,窗口名,窗口高度,窗口宽度);
*/
     public function jsOpenWin($url,$name,$height,$width){
        echo $this->jsStartChar;
        echo 'window.open'.'("'.$url.'","'.$name.'","'.$height.'","'.$width.'");';
        echo $this->jsEndChar;
     }

/*
*函数名称:jsAddscrīpt
*函数功能:自定义JS
*参数:$scrīpt
*使用方法:
*$scrīpt = '定义的js语句';
*例如:$scrīpt = 'window.location=(\'php.php\')';
*$js->jsAddscrīpt($scrīpt);
*/
     public function jsAddscrīpt($scrīpt){
        echo $this->jsStartChar;
        echo $scrīpt;
        echo $this->jsEndChar;
     }
}
?>
[/php] 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/317879.htmlTechArticle在web编程中大家应该会经常用到一些常用js操作,例如alert(),通常是遇到了再写,受公司的启发,我自己简单写了个类来自动生成这些...
Statement:
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