The following is an introduction to the extended portion of the prototype string object:
This section mainly adds several useful methods to the string object:
strip ():Remove white space on either side of the string, such as "JJ". Strip () return to "JJ"
striptags ():Get rid of HTML tags in strings
stripscripts ():Get rid of JavaScript code snippets in strings
extractscripts ():Returns the JavaScript code in the string, returning the array
evalscripts ():Executing JavaScript code in a string
escapehtml ():Converts the HTML code in a string to a format that can be displayed directly, such as converting < to IE6, having a bug in the box, executing the string returned by the operation, and turning a number of connected blanks into one, so that a lot of the newline is removed.
unescapehtml ():The reverse process of escapehtml
truncate (length, truncation):Truncation, such as "ABCDEFGHIGKL". Truncate (10) returns ABCDEFG ..., truncation defaults to "..."Toqueryparams (separator)/parsequery (separator):Converts a querystring into a hash table (in fact, an object that can be used as a hash table in JavaScript because the object's properties or methods can be accessed through Object[propertyname]
ToArray ():return This.split ('), converting to an array of characters
camelize ():Converts the form of background-color into a backgroundcolor form, used in STYLE/CSS
capitalize ():Returns a string with the first letter capitalized
Inspect (usedoublequotes):Returns the representation of a string, such as "sdfj\" SFA. Inspect () returns "' SDFJ ' SFA '"
gsub (pattern, replacement):Pattern is a regular expression, replacement is a function (or a template string) that uses replacement processing for each part of the string that matches pattern. The value returned by replacement is then replaced with the previously matched part, such as "SKDJFASFDJKADK". Gsub (/a/,function (match) {return match[0].tolowercase ()}), Converts all a of the string A to a, noting that the G option is not added in pattern, because Gsub will recursively execute the match method
Sub (pattern, replacement, count):Another form of gsub, but you can set the number of executions
Scan (pattern, iterator):Similar to Gsub, but returns the string itself, which means that the iterator is executed for each match in pattern, but the replacement string "SKDJFASFDJKADK" is not returned. Gsub (/a/,function () {alert ' have A A '})
underscore ():' borderBottomWidth '. underscore ()-> ' Border_bottom_width '
dasherize ():' Hello_world '. Dasherize ()-> ' Hello-world '
template template class:
How to use:
var template = new template (replacement, pattern);
Template.evaluate (object) is somewhat like a template in PHP, and by default (no pattern is provided) the { Something in the form of PropertyName} replaces the property value of object