PHP Simple encapsulation of some common JS operation _php Skills
Source: Internet
Author: User
In the Web programming, we should often use some common JS operations, such as alert (), usually encountered again write, inspired by the company, I wrote a simple class to automatically generate these JS, the purpose is to facilitate, a gadget, beginners may like ^_^
[PHP]
<?php
/*
* Page: makeJs.class.php
* Function: Encapsulate commonly used JS code, direct call, convenient operation
* Author: Boss FAI
* Date Created: 2007-01-27
*/
Class Makejs
{
Private $jsStartChar = "<scrīpt type=" text/javascrīpt ">";//define JS start tag
Private $jsEndChar = ' </scrīpt> ';//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 balloon $url click on the path of the jump, blank is not jump
* Use method:
* $js = new Makejs ()//The following describes using the method to omit this sentence
* $js->jsalert (display text, ' jump page URL ');/popup dialog box, click OK to jump to php.php page
* $js->jsalert (display text, "")//Pop-up dialog box, click OK after 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 ' <meta http-equiv= ' refresh ' c> ';
}
}
/*
* Function Name: jsconfirm
* Function function: Pop-up JS prompt box, with OK/Cancel
* Parameters: $message The text to be displayed in the pop-up prompt box
* Use method: $js->jsconfirm (' displayed text ');
*/
Public Function jsconfirm ($message) {
Echo $this->jsstartchar;
if ($url = = ") {
echo ' Confirm '. '("' . $message. '");';
Echo $this->jsendchar;
}
}
/*
* Function Name: Jsopenwin
* Function function: pop-up new window
* Parameters: $url path $name window name $height window height $width window width
* Use 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. "); ';
Echo $this->jsendchar;
}
/*
* Function Name: jsaddscrīpt
* Function function: Custom JS
* Parameter: $SCR īpt
* Use 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;
Echo $this->jsendchar;
}
}
?>
[/php]
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