Collect some rare and useful custom function code to calculate the JavaScript function Image Adaptive size function code of the JavaScript function before and after the characters to remove Spaces
Js functions that calculate the character Length
The Code is as follows:
Function LEN (str ){
Var I, sum = 0;
For (I = 0; I If (str. charCodeAt (I) >=0) & (str. charCodeAt (I) <= 255 ))
Sum = sum + 1;
Else
Sum = sum + 2;
}
Return sum;
}
Js functions that remove spaces before and after characters
The Code is as follows:
Function TRIM (value) {return value. replace (/^ \ s */, ''). replace (/\ s * $ /,'');}
Image Adaptive size function code
The Code is as follows:
Function imgAutoFit (imgObj, maxWidth, maxHeight ){
Var heightWidth;
Var widthHeight;
HeightWidth = imgObj. offsetHeight/imgObj. offsetWidth;
WidthHeight = imgObj. offsetWidth/imgObj. offsetHeight;
If (imgObj. offsetWidth> maxWidth ){
ImgObj. width = maxWidth;
ImgObj. height = maxWidth * heightWidth;
}
If (imgObj. offsetHeight> maxHeight ){
ImgObj. height = maxHeight;
ImgObj. width = maxHeight * widthHeight;
}
}
Function checkTagIsHave (s, t ){
Var re = new RegExp ("<\\/? "+ T + "(? :(? : \ S | \\/)(? : \ N |.) *?)?> "," Ig ");
Var r = re. test (s );
Re = null;
Return r;
}
Function imgUploadFit (){
Var u = document. getElementsByName ("imgUploadName ");
If (0 = u. length) return;
For (var I = 0; I // ImgAutoFit (u [I], 560,560 );
ImgAutoFit (u [I], 320,320 );
U [I]. onclick = function () {window. open (this. src );}
U [I]. style. cursor = "pointer ";
U [I]. title = "click to view the source image ";
}
}
Function inputContent (theQ, oldContent, re, p ){
Var o, oA = ["msgframeamend", "pingJiaFrame", "touSuFrame"];
For (o in oA ){
If ($ (oA [o]) {
TheQ. editIframe (oA [o]);
If ("msgframeamend" = oA [o]) settimeout(function()[((oaoaoa.contentdoc Doc ument. body. innerHTML = oldContent. replace (re, "") + p [1];}, 100 );
Return;
}
}
}
Function checkCommon (n, v, t ){
Var s = t? "Supplemental question": "Reply content ";
Var o = document. getElementById (n). contentWindow;
If ("msgframereply" = n ){
If (v = ""){
Alert ("enter" + s + "! ");
O. focus ();
Return false;
}
}
If ("" = v. replace (/<\/*? (? : Img | p | pre | br )(? :(? : \ S | \/)(? : \ N |.) *?)?> | \ S |/ig, "") & checkTagIsHave (v, "img ")){
Alert ("For images, please attach some descriptive text! ");
O. focus ();
Return false;
}
If (1, 10000 Alert (s + "exceeds the limit of 5000 words! ");
O. focus ();
Return false;
}
Return true;
}