jquery Getting started the next day &&& regular expression end--making of imitation smarty engine, Introduction to jquery
Hi
Monday completely not in the state ... Noon also to the spectator, did not sleep me, the night smarty do not know can finish, refueling bar
1. JQuery
---filter selector (ii)---
--[attribute=value] Property Selector
property as an important feature of a DOM element or in a selector, the selector for getting elements through element properties is introduced from this section, and [attribute=value]
the function of the property selector is to get all the elements that are exactly the same as the property name and property value, where [] is a brace character that is dedicated to the property selector. The parameter attribute represents the property name, and the value parameter represents the property values.
Change the background color of the "title" property value to "vegetable"
- Eggplant
- Banana
- Celery
- Apple
- Watermelon
--:text Form Text Selector
:text
The form text selector can get all the lines of text input box elements in the form, and a single line of text input boxes is like a non-wrapping note tool that is widely used.
Modify the background color of multiple single-line input box elements
--:p assword form password Selector
If you want to get the password input text box, you can use the :password
selector, which is the function of getting all the password input text box elements in the form.
Modify the background color of multiple password input box elements
--:radio radio Button Selector
Radio buttons in a form are often used for only one selection in multiple data, and :radio
a selector makes it easy to get all the radio button elements in a form.
Set the radio button in the form to not available
--:checkbox check box Selector
The checkboxes in the form are often used for the selection of multiple data, and :checkbox
you can use selectors to quickly locate and get the check box elements in the form.
Make all the check boxes for the form unavailable
--:submit Submit Button Selector
Typically, only one submit button with a "type" attribute value of "submit" is allowed in a form, and :submit
the selector can be used to get the submit button element in the form.
Modify the background color of the submit button in a form
--:image Image Domain Selector
When aWhen the element's "type" property value is set to "image", the element is an image field, and the :image
selector can be used to quickly get all the elements of that class.
Modify the background color of an image element in a form
--:button Form Button Selector
There are many types of buttons in the form, and using the:button
The selector can get and get only the "type" property value of "button".AndThese two types of common button elements.
Modify the background color of a button element in a form
--:checked Selected State Selector
Some elements are selected, such as check boxes, radio button elements, and when selected, the value of the Checked property is "checked", called: checked can get all the elements that are in the selected state.
Set the selected element to not available
--:selected Selected State Selector
And:checked
Selector compared to the:selected
Selectors can only getThe drop-down list box is all selected in theThe option element. Gets the contents of the element in the selected state ----------------------------------------------------------------2. Regular expressionsThe purpose of the engine template here is to replace the variable output.What you need is the template file. class, which compiles the source files. php--template.class.php /** Description: Imitation smarty Template engine class file**/Class template{Private $templateDir; Used to store source files in the same directoryPrivate $compileDir; Used to store the compiled file directoryPrivate $leftTag = ' {# ';//the tag of the object to be replaced, smarty default is {Private $rightTag = ' #} ';Private $currentTemp = '; Used to store the template file name that is currently being compiledPrivate $outputHtml; HTML code to store the CurrenttempPrivate $varpool =array (); Variable pool; Template compile-time store variablesPublic function __construct ($templateDir, $compileDir, $leftTag =null, $rightTag =null) {$this->templatedir= $templateDir;$this->compiledir= $compileDir;if (!empty ($LEFTTAG)) $this->lefttag= $leftTag; When passing the left and right markers, you need to make a non-empty judgment.if (!empty ($RIGHTTAG)) $this->righttag= $rightTag;}Assign function--put the variables needed in the template into the address pool, and given the tagPublic function assign ($tag, $var) {$this->varpool[$tag]= $var;}Corresponding to the above assign, remove the variable from the address poolPublic Function GetVar ($tag) {return $this->varpool[$tag];}Getsourcetemplate: Get compiled source file _ need to know the file name, and the full path (so to have the extension namePublic Function Getsourcetemplate ($templateName, $ext = '. html ') {$this->currenttemp= $templateName;$sourceFilename = $this->templatedir. $this->currenttemp. $ext;$this->outputhtml=file_get_contents ($sourceFilename);}Compiletemplate: Compilation methodPublic Function Compiletemplate ($templateName =null, $ext = '. html ') {$templateName =empty ($templateName)? $this->currenttemp: $templateName;Core code, regular compilation\{#\$ (\w+) #\}$pattern = '/\{#\$ (\w+) #\}/';A clearer notation $pattern= '/'. Preg_quote ($this->lefttag). ' *\$ ([a-za-z_]\w*) * '. Preg_quote ($this->righttag). ' /';The core code to do is to find something inside the tag and replace it with what PHP can recognize.$this->outputhtml=preg_replace ($pattern, ' GetVar (\ ' $1\ ')?> ', $this->outputhtml);Note the usage of the preg_replace here, which represents the matching sub-patternThe following will generate the target file, as well as the full target path$compiledFilename = $this->compiledir.md5 ($templateName). $ext;File_put_contents ($compiledFilename, $this->outputhtml);}Public function display ($templateName = null, $ext = '. html ') {$templateName = Empty ($templateName)? $this->currenttemp: $templateName;Include_once $this->compiledir.md5 ($templateName). $ext;}}--index.php /** Cottage Template Engine test file*/Include fileRequire_once ' template.class.php ';Get path, Basedir root directory$baseDir =str_replace (' \ \ ', '/', dirname (__file__));$temp =new Template ($baseDir. ' /source/', $baseDir. ' /compliled/');Variable Pool$temp->assign (' pagetitle ', ' Cottage version Smarty ');$temp->assign (' Test ', ' Imooc goddess ');//$temp->getsourcetemplate (' index ');$temp->compiletemplate ();$temp->display ();--A few points to noteFollow the property + method, compile the pipeline as wellThen, some services to open, or like me, but also to debug ...Good luck to all of you. Http://www.bkjia.com/PHPjc/1067097.htmlWww.bkjia.comTrueHttp://www.bkjia.com/PHPjc/1067097.htmlTecharticlejquery Getting started the next day regular expression end--imitation smarty engine production, jquery primer hi Monday completely not in the state ... Noon also went to watch, did not sleep me, night's ...