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 the integer/random number
Math.ceil ()
Ceil () method rounds 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. The
Math.floor ()
Floor () method can be rounded down by one 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. The
Math.Round ()
Round () method rounds a number to the nearest integer
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: 4
Math.Round (4.8992303) output: 5
Math.ceil ( 4.29993354) Output Result: 5
Math.floor (4.29993354) Output result: 4
Math.Round (4.29993354) output: 4
Math.Round (Math.random () * 100); Generates a random number of 0-100
4. Intercepts the string
var txt=$ ("P"). Text (). substr (0,15);//intercept 15 characters starting with 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;
}
Transferred from: http://www.cnblogs.com/X-Jonney/p/5529874.html
Jquery Processing strings