Python Road _day86_blog Review Building

Source: Internet
Author: User

One, custom attributes

We know that in the process of front-end page rendering, we may need to use some back-end parameters, the acquisition of this parameter is generally rendered through the template language. But when these parameters are used in the JS file (JS code if the file is a separate reference, template language can not be rendered), how to do? We can write a label that is not actually useful on the page, by customizing the property to this tag to hold the parameters we want. Examples are as follows:

Then, we can find this tag in the JS code, then we can take the corresponding custom properties, the application example is as follows:

Second, JSON supplement

For example, when it comes to the types of JSON objects that can be accepted in JS and Python, only the data types shown in the 5 are serialized, and it is obvious that JSON is not used to serialize the date object, but the time type in our models is the Date object. What do we do if we need to pass this date object through serialization to the front end?

The following example, in Python, converts a Date object to a specified form of time string by Strftime, and then serializes it, with the following example:

The function and method of string object in JS

The specific methods and functions are described as follows:

X.length-----get the length of the string X.tolowercase ()---to lowercase x.touppercase ()----to uppercase X.trim ()- ----String Query method X.charat (Index)----str1.charat (index)-----Gets the specified position character, where index is the character index to get X.indexof (FINDST        R,index)-----query string position x.lastindexof (findstr) x.match (regexp)----match returns an array of matched strings and returns Nullx.search if no match (regexp) ----search Returns an example of the first character position index of a matching string:varStr1= "Welcome to the world of js!"; varStr2=str1.match ("World"); varStr3=str1.search ("World"); Alert (str2[0]);//The result is "world"alert (STR3);//The result is----- substring processing method x.substr (start, length)----start represents the start position, length indicates the Intercept length x.substring (start, end)----en D is the end position x.slice (start, end)----example of a slice manipulation string:varstr1= "ABCDEFGH"; varStr2=str1.slice (2,4); varStr3=str1.slice (4); varStr4=str1.slice (2,-1); varStr5=str1.slice ( -3,-1); alert (STR2); //The result is "CD"alert (STR3);//The result is "EFGH"alert (STR4);//The result is "CDEFG"alert (STR5);//The result is "FG"X.replace (FINDSTR,TOSTR)----string substitution x.split (); ---split stringvarStr1= "One, two, three, four, five, six, day"; varStrarray=str1.split (","); Alert (strarray[1]);//The result is "two"X.concat (ADDSTR)---stitching strings

In JS, it is necessary to use the slice () method to slice the string, the application example is as follows:

Four, Dom object focus

In our blog project, we need to comment on the existing comments, we need to click on the corresponding "Reply" button, click on any "Reply" button, we need to focus on the comment input box, this time we will use the focus () method, the specific application example is as follows:

Five, JS in parseint ()

The contents of the HTML tag, even the numbers, but when we get through the text method, which is actually the data type of the string, when we need to convert it to a data type, we need to use the parseint () method, which is the method of converting a string of numbers into a numeric type. The application examples are as follows:

Python Road _day86_blog Review Building

Related Article

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.