PHP Simple encapsulation of some common JS operation _php Tutorial

Source: Internet
Author: User
In the Web programming people should often use some common JS operations, such as alert (), usually encountered a re-write, inspired by the company, I wrote a simple class to automatically generate these JS, the purpose is to facilitate, a gadget, novices may like ^_^
[PHP]
/*
* Page: makeJs.class.php
* Function: Packaging common JS code, direct call, easy to operate
* Author: Hui boss
* Date Created: 2007-01-27
*/
Class Makejs
{
Private $jsStartChar = ' ';//define JS start tag
Private $jsEndChar = ' ';//define JS end tag

/*
* Function Name: Jsalert
* Function function: Popup JS prompt box
* Parameters: $message The text to be displayed in the pop-up prompt $url the path to jump after the click, the blank does not jump
* How to use:
* $js = new Makejs ();//The following describes how to omit this sentence
* $js->jsalert (display text, ' jump page URL '),//Popup dialog, click OK to jump to php.php page
* $js->jsalert (displayed text, ');//Popup dialog box, click OK and no jump
*/
Public Function Jsalert ($message, $url) {
Echo $this->jsstartchar;
if ($url = = ") {
echo ' alert '. '("' . $message. '");';
Echo $this->jsendchar;
}
else{
echo ' alert '. '("' . $message. '");';
Echo $this->jsendchar;
Echo ' ';
}
}

/*
* Function Name: jsconfirm
* Function function: Popup js prompt box with OK/Cancel
* Parameters: $message The text to display in the popup prompt box
* How to use: $js->jsconfirm (' displayed text ');
*/
Public Function jsconfirm ($message) {
Echo $this->jsstartchar;
if ($url = = ") {
echo ' Confirm '. '("' . $message. '");';
Echo $this->jsendchar;
}
}

/*
* Function Name: Jsopenwin
* Function function: Popup new Window
* Parameters: $url path $name window name $height window height $width window width
* How to use:
* $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. '");
Echo $this->jsendchar;
}

/*
* Function Name: jsaddscrīpt
* Function function: Custom JS
* Parameters: $scr īpt
* How to use:
* $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;
Echo $this->jsendchar;
}
}
?>
[/php]

http://www.bkjia.com/PHPjc/317879.html www.bkjia.com true http://www.bkjia.com/PHPjc/317879.html techarticle in the Web programming people should often use some common JS operations, such as alert (), usually encountered a re-write, inspired by the company, I wrote a simple class to automatically generate these ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.