php簡單封裝了一些常用JS操作
更新時間:2007年02月25日 00:00:00 作者:
在web編程中大家應(yīng)該會經(jīng)常用到一些常用js操作,例如 alert(),通常是遇到了再寫,受公司的啟發(fā),我自己簡單寫了個類來自動生成這些js,目的就是為了方便,一個小玩意,新手們也許會喜歡^_^
[php]
<?php
/*
*頁面:makeJs.class.php
*功能:封裝常用的JS代碼,直接調(diào)用,方便操作
*作者:輝老大
*創(chuàng)建時間:2007-01-27
*/
class makeJs
{
private $jsStartChar = '<scrīpt type="text/javascrīpt">';//定義js起始標(biāo)記
private $jsEndChar = '</scrīpt>';//定義js結(jié)束標(biāo)記
/*
*函數(shù)名稱:jsAlert
*函數(shù)功能:彈出JS提示框
*參數(shù):$message 要在彈出提示框中顯示的文字 $url 點(diǎn)擊后跳轉(zhuǎn)的路徑,為空則不跳轉(zhuǎn)
*使用方法:
*$js = new makeJs();//以下介紹使用方法省略此句
*$js->jsAlert(顯示的文字,'跳轉(zhuǎn)頁面URL');//彈出對話框,點(diǎn)擊確定后跳轉(zhuǎn)到php.php頁面
*$js->jsAlert(顯示的文字,'');//彈出對話框,點(diǎn)擊確定后沒有跳轉(zhuǎn)
*/
public function jsAlert($message,$url){
echo $this->jsStartChar;
if($url==''){
echo 'alert' . '("' . $message . '");';
echo $this->jsEndChar;
}
else{
echo 'alert' . '("' . $message . '");';
echo $this->jsEndChar;
echo '<meta http-equiv="refresh" c>';
}
}
/*
*函數(shù)名稱:jsConfirm
*函數(shù)功能:彈出JS提示框,帶確定/取消
*參數(shù):$message 要在彈出提示框中顯示的文字
*使用方法:$js->jsConfirm('顯示的文字');
*/
public function jsConfirm($message){
echo $this->jsStartChar;
if($url==''){
echo 'confirm' . '("' . $message . '");';
echo $this->jsEndChar;
}
}
/*
*函數(shù)名稱:jsOpenWin
*函數(shù)功能:彈出新窗口
*參數(shù):$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;
}
/*
*函數(shù)名稱:jsAddscrīpt
*函數(shù)功能:自定義JS
*參數(shù):$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]
[php]
<?php
/*
*頁面:makeJs.class.php
*功能:封裝常用的JS代碼,直接調(diào)用,方便操作
*作者:輝老大
*創(chuàng)建時間:2007-01-27
*/
class makeJs
{
private $jsStartChar = '<scrīpt type="text/javascrīpt">';//定義js起始標(biāo)記
private $jsEndChar = '</scrīpt>';//定義js結(jié)束標(biāo)記
/*
*函數(shù)名稱:jsAlert
*函數(shù)功能:彈出JS提示框
*參數(shù):$message 要在彈出提示框中顯示的文字 $url 點(diǎn)擊后跳轉(zhuǎn)的路徑,為空則不跳轉(zhuǎn)
*使用方法:
*$js = new makeJs();//以下介紹使用方法省略此句
*$js->jsAlert(顯示的文字,'跳轉(zhuǎn)頁面URL');//彈出對話框,點(diǎn)擊確定后跳轉(zhuǎn)到php.php頁面
*$js->jsAlert(顯示的文字,'');//彈出對話框,點(diǎn)擊確定后沒有跳轉(zhuǎn)
*/
public function jsAlert($message,$url){
echo $this->jsStartChar;
if($url==''){
echo 'alert' . '("' . $message . '");';
echo $this->jsEndChar;
}
else{
echo 'alert' . '("' . $message . '");';
echo $this->jsEndChar;
echo '<meta http-equiv="refresh" c>';
}
}
/*
*函數(shù)名稱:jsConfirm
*函數(shù)功能:彈出JS提示框,帶確定/取消
*參數(shù):$message 要在彈出提示框中顯示的文字
*使用方法:$js->jsConfirm('顯示的文字');
*/
public function jsConfirm($message){
echo $this->jsStartChar;
if($url==''){
echo 'confirm' . '("' . $message . '");';
echo $this->jsEndChar;
}
}
/*
*函數(shù)名稱:jsOpenWin
*函數(shù)功能:彈出新窗口
*參數(shù):$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;
}
/*
*函數(shù)名稱:jsAddscrīpt
*函數(shù)功能:自定義JS
*參數(shù):$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]
相關(guān)文章
php實(shí)現(xiàn)自動生成驗(yàn)證碼的實(shí)例講解
在本篇文章里小編給大家整理了一篇關(guān)于php實(shí)現(xiàn)自動生成驗(yàn)證碼的實(shí)例講解內(nèi)容,有需要的朋友們可以跟著學(xué)習(xí)下。2021-10-10
PHP四種統(tǒng)計(jì)在線人數(shù)方式詳細(xì)介紹
這篇文章主要介紹了用PHP來統(tǒng)計(jì)在線人數(shù)的四個方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧2022-09-09
jquery獲取多個checkbox的值異步提交給php的方法
這篇文章主要介紹了jquery獲取多個checkbox的值異步提交給php的方法,涉及jQuery操作頁面元素進(jìn)行異步傳輸?shù)南嚓P(guān)技巧,需要的朋友可以參考下2015-06-06

