Home > Backend Development > PHP Tutorial > PHP simply encapsulates some common JS operations_PHP tutorial

PHP simply encapsulates some common JS operations_PHP tutorial

WBOY
Release: 2016-07-21 15:57:06
Original
1192 people have browsed it

In web programming, you should often use some common js operations, such as alert(). Usually, you write them when you encounter them. Inspired by the company, I simply wrote a class to automatically generate these js. The purpose is for convenience. A gadget that novices may like ^_^
[php]
/*
*Page: makeJs.class.php
*Function: Encapsulate commonly used JS code, directly called, easy to operate
*Author: Hui Boss
*Creation time: 2007-01-27
*/
class makeJs
{
private $jsStartChar = ' ';//Define js start tag
private $jsEndChar = '
';//Define js end tag

/*
*Function name: jsAlert
*Function function: pop up JS prompt box
*Parameters: $message The text to be displayed in the pop-up prompt box $url The path to jump after clicking, if it is empty, it will not jump Go to
* Usage:
*$js = new makeJs();//The following introduction uses the method to omit this sentence
*$js->jsAlert (displayed text, 'Jump page URL' );//A dialog box pops up, click OK and jump to the php.php page
*$js->jsAlert(displayed text,'');//A dialog box pops up, there is no jump after clicking OK
*/
public function jsAlert($message,$url){
echo $this->jsStartChar;
if($url==''){
echo 'alert' . '("' . $message . '");';
echo $this->jsEndChar;
}
else{
echo 'alert'. '("' . age. '");';
echo $this->jsEndChar;
echo '';
}
}

/*
*Function name: jsConfirm
*Function function: Pop up JS prompt box with confirmation/cancel
*Parameter: $message Text to be displayed in the pop-up prompt box
*Usage method: $js->jsConfirm('displayed text');
*/
public function jsConfirm($message){
echo $this->jsStartChar;
if($url== '') { Echo 'Confirm'. '("'. $ Message. '");'; >/*
*Function name: jsOpenWin
*Function function: pop up a new window
*Parameters: $url path $name window name $height window height $width window width
*Usage method:
*$url = 'URL of the page';
*$js->jsOpenWin($url, window name, window height, window width);
*/
public function jsOpenWin($url ,$name,$height,$width){
echo $this->jsStartChar;
echo 'window.open'.'("'.$url.'","'.$name.' ","'.$height.'","'.$width.'");';
                                                                                                                                                                            Function name: jsAddscrīpt
*Function function: Custom JS
*Parameter: $scrīpt
*Usage method:
*$scrīpt = 'defined js statement';
*For example: $ scrīpt = 'window.location=('php.php')';
*$js->jsAddscrīpt($scrīpt);
*/
public function jsAddscrīpt($scrīpt){
echo $this->jsStartChar;
echo $scrīpt;

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/317879.htmlTechArticleIn web programming, you should often use some common js operations, such as alert(), usually when you encounter Writing again, inspired by the company, I simply wrote a class to automatically generate these...

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template