Prototype User Guide-string. js

Source: Internet
Author: User

The following describes how Prototype extends String objects:

This section mainly adds several useful methods to the string object:

Strip ():Removes the white space on both sides of the string. For example, "jj". strip () returns "jj"
StripTags ():Remove the html tag from the string.
StripScripts ():Removes the javascript code segment from the string.
ExtractScripts ():Returns the javascript code in the string and an array.
EvalScripts ():Execute the javascript code in the string
EscapeHTML ():Convert the html code in the string to a format that can be directly displayed. For example, if you convert <to <, and there is a bug in ie6, the string returned by performing this operation, multiple blank links are converted into one, so many new lines are removed.
UnescapeHTML ():Reverse process of escapeHTML
Truncate (length, truncation ):Truncation. For example, "abcdefghigkl". truncate (10) returns abcdefg..., and truncation defaults "..."ToQueryParams (separator)/parseQuery (separator ):Convert a querystring into a hash table (in fact, an object can be used as a hash table in javascript, because the object's attributes or methods can be accessed through object [propertyName)
ToArray ():Return this. split (''), converted to a character array
Camelize ():Convert the form of background-color to the form of backgroundColor and use it in style/css.
Capitalize ():Returns an uppercase string.
Inspect (useDoubleQuotes ):Returns the string representation. For example, "sdfj \" sfa ". inspect () returns" 'sdfj "sfa '"
Gsub (pattern, replacement ):Pattern is a regular expression, and replacement is a function (or a template string). replacement is used to process each part of the string that matches pattern, then replace the value returned by replacement with the original matching part, for example, "skdjfAsfdjkAdk ". gsub (/A/, function (match) {return match [0]. toLowerCase ()}) to convert all A values of the string to a. do not add the g option to pattern because gsub recursively executes the match method.
Sub (pattern, replacement, count ):Gsub is another form, but the number of executions can be set.
Scan (pattern, iterator ):Similar to gsub, but returns the string itself. That is to say, iterator is executed for each matching in pattern, but the replaced string "skdjfAsfdjkAdk" is not returned ". gsub (/A/, function () {alert 'have '})
Underscore ():'Borderbottomwidth '. underscore ()-> 'border _ bottom_width'
Dasherize ():'Hello _ world'. dasherize ()-> 'hello-world'
Template class:
Usage:
Var template = new Template (replacement, pattern );
Template. evaluate (object) is a bit like a template in php. By default (pattern is not provided), the object attribute value is replaced with the {propertyName} format.

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.