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 = '
private $jsEndChar = '
/*
*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== '') {
*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;