JS processing string

Source: Internet
Author: User
/*** Word truncation plug-in * wordlimit (OBJ); automatically obtains the CSS width for processing. If no width is specified for the jquery object OBJ in CSS, * wordlimit (OBJ, 24). Number of truncated characters. The value must be an integer greater than 0. The number of characters in the label of the jquery object OBJ can be 24 at most */wordlimit: function (OBJ, num) {obj. each (function () {If (! Num) {var copythis = (this.clonenode(true+}.hide().css ({'position': 'absolute ', 'width': 'auto', 'overflow': 'visable'}); $ (this ). after (copythis); If (copythis. width ()> trim () + '... '); copythis. remove (); COM. UE. util. wordlimit ($ (this);} else {copythis. remove (); // Clear copy return;} else {var maxwidth = num; if ($ (this ). text (). length> values () + '... ') ;}}) ;},/*** limit the maximum Div height. * controldivheight ('purformdiv', '123'); */controldivheight: function (OBJ, maxheight) {obj.css ("height", "Auto"); If (obj. height ()> maxheight) {obj.css ("height", maxheight + "PX"); obj.css ("overflow-y", "scroll ");}}
 
 
 
 
 
 

/*** Determine whether the string ends with a certain character * @ Param {object} S1 * @ Param {object} S2 * @ return {typename} */string. prototype. endwith = function endwith (STR) {If (this. length <Str. length) return false; If (this = Str) return true; If (this. substring (this. length-Str. length) = Str) Return
True; return false;}/*** use a regular expression to replace spaces with empty strings */string. prototype. trim = function () {return this. replace (/(^ \ s *) | (\ s * $)/g, "");}/*** replaceall */string. prototype. replaceall = function (S1, S2) {var r = new Regexp (s1.replace (/([\(\) \ [\] \ {\}\^\$ \+ \-\*\? \. \ "\ '\ | \/\])/G," \ $1 "),
"Ig"); return this. Replace (R, S2 );}

 

 

 

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.