HomeBackend DevelopmentPHP TutorialThe second day of getting started with jQuery &&& The end of regular expressions - making a smarty-like engine, getting started with jQuery_PHP tutorial
The second day of getting started with jQuery &&& The end of regular expressions - making a smarty-like engine, getting started with jQuery_PHP tutorial
The second day of getting started with jQuery&&®ular expression completion - making a smarty-like engine, getting started with jquery
Hi
Completely out of shape on Monday. . . I went to watch the game at noon. I didn’t sleep. I don’t know if I can finish the smarty at night. Come on
1. jQuery
---Filter selector (2)---
--[attribute=value]Attribute selector
As an important feature of DOM elements, attributes can also be used in selectors. Starting from this section, we will introduce selectors for obtaining elements through element attributes. The function of [attribute=value]attribute selectors is to obtain attribute names and attribute values. All elements are exactly the same, where [] is the bracket symbol used specifically for attribute selectors, the parameter attribute represents the attribute name, and the value parameter represents the attribute value.
Change the background color of the "title" attribute value to "Vegetables"
Eggplant
Banana
celery
Apple
Watermelon
--:text form text selector
:textThe form text selector can obtain all single-line text input box elements in the form. The single-line text input box is like a note tool without line breaks and is very widely used.
Modify the background color of multiple single-line input box elements
--:password form password selector
If you want to get the password input text box, you can use the :password selector. Its function is to get all the password input text box elements in the form.
Modify the background color of multiple password input box elements
--:radio button selector
Radio buttons in a form are often used to select only one of multiple items of data, and using the :radio selector can easily obtain the all radio button elements in the form.
Set the radio button in the form to be disabled
--:checkbox checkbox selector
Check boxes in forms are often used to select multiple data. Use the :checkbox selector to quickly locate and obtain the check box elements in the form.
Set all checkboxes in the form to disabled
--:submit button selector
Normally, only one submit button with a "type" attribute value of "submit" is allowed in a form. Use the :submit selector to get the Submit button element in the form.
Modify the background color of the submit button in the form
--:image image domain selector
When the "type" attribute value of an element is set to "image", the element is an image field. Use the :image selector to quickly obtain all elements of this type.
Modify the background color of image elements in the form
--:button form button selector
The
form contains many types of buttons, and the :button selector can be used to obtain and only obtain two types of ordinary button elements, and
Modify the background color of the button element in the form
--:checked selected state selector
Some elements have a selected state, such as check boxes and radio button elements. When selected, the "checked" attribute value is "checked". Calling: checked can get all elements in the selected state.
class template{ private $templateDir; //Used to store the directory where the source files are located private $compileDir; //Used to store the compiled file directory private $leftTag='{#' ; //The tag of the object to be replaced, smarty defaults to { private $rightTag='#}'; private $currentTemp=''; //Used to store the name of the template file currently being compiled private $outputHtml; //HTML code used to store currentTemp private $varpool=array(); //Variable pool; variables are stored during template compilation
public function __construct($templateDir,$compileDir ,$leftTag=null,$rightTag=null){ $this->templateDir=$templateDir; $this->compileDir=$compileDir; if (!empty($leftTag)) $this->leftTag=$leftTag; //When passing left and right tags, 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 give the tag public function assign($tag,$var){ $ this->varpool[$tag]=$var; }
//Corresponding to the assignment above, take out the variable from the address pool public function getVar($tag){ return $this->varpool[$tag]; }
//getSourceTemplate: Get the compiled source file_You need to know the file name and full path (so you need an extension public function getSourceTemplate($templateName,$ext='.html'){ $this->currentTemp=$templateName; $sourceFilename=$this->templateDir.$this->currentTemp. $ext; $this->outputHtml=file_get_contents($sourceFilename); }
//compileTemplate: Compile method public function compileTemplate($templateName=null,$ext= '.html'){ $templateName=empty($templateName)? $this->currentTemp:$templateName; //Core code, regular compilation //{#$(w )# } $pattern='/{#$(w )#}/'; //Clearer writing $pattern='/'.preg_quote($this->leftTag).' *$( [a-zA-Z_]w*) *'.preg_quote($this->rightTag).'/'; //What the core code has to do is to find the thing in the tag, and then replace it with something that PHP can recognize Content $this->outputHtml=preg_replace($pattern, 'getVar('$1')?>', $this->outputHtml); //Note the usage of preg_replace here, $1 represents the matching sub-pattern
//Generate the target file below, which also requires the complete 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; }
Follow the attribute method and compile like a pipeline
Then, some services need to be opened, otherwise like me, you still need to debug. . .
Good luck to everyone.
http://www.bkjia.com/PHPjc/1067097.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1067097.htmlTechArticleJQuery Getting Started with Regular Expressions on the Second Day - The Production of Imitation Smarty Engine, Getting Started with jQuery hi Complete on Monday Out of state. . . I went to watch the game at noon. I didn’t sleep. At night...
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
Detailed explanation of jQuery reference method: Quick start guide jQuery is a popular JavaScript library that is widely used in website development. It simplifies JavaScript programming and provides developers with rich functions and features. This article will introduce jQuery's reference method in detail and provide specific code examples to help readers get started quickly. Introducing jQuery First, we need to introduce the jQuery library into the HTML file. It can be introduced through a CDN link or downloaded
How to use PUT request method in jQuery? In jQuery, the method of sending a PUT request is similar to sending other types of requests, but you need to pay attention to some details and parameter settings. PUT requests are typically used to update resources, such as updating data in a database or updating files on the server. The following is a specific code example using the PUT request method in jQuery. First, make sure you include the jQuery library file, then you can send a PUT request via: $.ajax({u
How to remove the height attribute of an element with jQuery? In front-end development, we often encounter the need to manipulate the height attributes of elements. Sometimes, we may need to dynamically change the height of an element, and sometimes we need to remove the height attribute of an element. This article will introduce how to use jQuery to remove the height attribute of an element and provide specific code examples. Before using jQuery to operate the height attribute, we first need to understand the height attribute in CSS. The height attribute is used to set the height of an element
jQuery is a fast, small, feature-rich JavaScript library widely used in front-end development. Since its release in 2006, jQuery has become one of the tools of choice for many developers, but in practical applications, it also has some advantages and disadvantages. This article will deeply analyze the advantages and disadvantages of jQuery and illustrate it with specific code examples. Advantages: 1. Concise syntax jQuery's syntax design is concise and clear, which can greatly improve the readability and writing efficiency of the code. for example,
Title: jQuery Tips: Quickly modify the text of all a tags on the page In web development, we often need to modify and operate elements on the page. When using jQuery, sometimes you need to modify the text content of all a tags in the page at once, which can save time and energy. The following will introduce how to use jQuery to quickly modify the text of all a tags on the page, and give specific code examples. First, we need to introduce the jQuery library file and ensure that the following code is introduced into the page: <
Title: Use jQuery to modify the text content of all a tags. jQuery is a popular JavaScript library that is widely used to handle DOM operations. In web development, we often encounter the need to modify the text content of the link tag (a tag) on the page. This article will explain how to use jQuery to achieve this goal, and provide specific code examples. First, we need to introduce the jQuery library into the page. Add the following code in the HTML file:
How to tell if a jQuery element has a specific attribute? When using jQuery to operate DOM elements, you often encounter situations where you need to determine whether an element has a specific attribute. In this case, we can easily implement this function with the help of the methods provided by jQuery. The following will introduce two commonly used methods to determine whether a jQuery element has specific attributes, and attach specific code examples. Method 1: Use the attr() method and typeof operator // to determine whether the element has a specific attribute
jQuery is a popular JavaScript library that is widely used to handle DOM manipulation and event handling in web pages. In jQuery, the eq() method is used to select elements at a specified index position. The specific usage and application scenarios are as follows. In jQuery, the eq() method selects the element at a specified index position. Index positions start counting from 0, i.e. the index of the first element is 0, the index of the second element is 1, and so on. The syntax of the eq() method is as follows: $("s