1. Remove spaces
var Txt=$.trim ($ ("Txt1"). Val ());
2. Convert to Digital
Txtnum=number ($.trim (TXT)) + 1;
var Thisele = $ ("#para"). CSS ("font-size"); Get font Size
var textfontsize = parsefloat (Thisele, 10);
3. Rounding to integers/random numbers
Math.ceil ()
The Ceil () method rounds up a number.
The parameter must be a numeric value. The return value is greater than or equal to X, and the integer closest to it.
Math.floor ()
The floor () method can be rounded down by a number.
The parameter can be any numeric value or expression. The return value is less than or equal to X and is the nearest integer to X.
Math.Round ()
The round () method rounds a number to the nearest integer
The parameter must be a numeric value. The return value is the nearest integer to X.
Math.ceil (4.8992303) output results: 5
Math.floor (4.8992303) output results: 4
Math.Round (4.8992303) output results: 5
Math.ceil (4.29993354) output results: 5
Math.floor (4.29993354) output results: 4
Math.Round (4.29993354) output results: 4
Math.Round (Math.random () *100); Generate 0-100 of random numbers
4. Intercepting strings
var txt=$ ("P"). Text (). substr (0,15);//intercept 15 characters starting from the first character
5. String substitution
$ ("image"). attr ("src"). Replace ("size=60", "size=200"); Usage replace (target to replace, new value replaced)
Match a regular replacement such as: $ ("#txt"). Replace (/[^\d-]/g, ""). Replace (/^\-/g, "");
6. Splitting a string
var str=new String ();
var arr=new Array ();
Str= "Baidu, farmer it station, Google, Bamboo Wind, nongfuit.com, Web Exchange Group, 180550045 Welcome to join";
Arr=str.split (', ');//note split can be separated by character or string
Alert (Str.split (', ') [1]);
for (Var i=0;i<arr.length;i++)
{
Alter (Arr[i]);
}
7.js and jquery objects convert to each other
var AA = $ ("#mm"). Get (0); jquery object into JS object
var bb = $ (AA); JS object into jquery object
8. Using regular matching
var Matchtel =/^ (([0\+]\d{2,3}-)? ( 0\d{2,3})-) (\d{7,8}) (-(\d{3,}))? $/;
if (!matchtel.test ($ ("#txtTel"). Val ())) {
Alert ("Phone format is wrong! ");
Return! 1;
}
Jquery Processing strings