Removes spaces at the beginning and end of a string.
JQuery code:
Copy codeThe Code is as follows:
$. Trim ("hello, how are you? ");
Jquery cyclically reads the checkbox Value
Copy the Code as follows:
Copy codeThe Code is as follows:
$ ("Input [type = checkbox] [checked]"). each (function () {// Since multiple check boxes are selected, You can output them cyclically.
Alert ($ (this). val ());
});
$ ("# "). The value of val ("1") id as A is 1 in jQuery. When assigning values, it is passed as A parameter to the function, which is different from js alone,
Like $ ("# A" ).html ("1") $ ("# "). all text ("1") values are assigned $ ("# A" ).html () $ ("# "). both text () and text () are values. The values are html,
Retrieve text
Method 1:
Copy codeThe Code is as follows:
Watermarks ('regionid').css ('display', 'None ');
Watermarks ('regionid').css ('display', 'block ');
Method 2:
Copy codeThe Code is as follows:
$ ('# Id'). hide ();
$ ('# Id'). show ();
Radio button group, name = "sex ".
Copy codeThe Code is as follows:
<Input type = "radio" name = "sex" value = "Male"> Male </input>
<Input type = "radio" name = "sex" value = "Female"> Female </input>
<Input type = "radio" name = "sex" value = "Unknown"> Unknown </input>
1. Obtain the value selected by radio.
Copy codeThe Code is as follows:
$ ('Input: radio [name = sex]: checked'). val ();
2. Select the radio button (Male ).
Copy codeThe Code is as follows:
$ ('Input: radio [name = sex]: nth (0) '). attr ('checked', true );
Or
Copy codeThe Code is as follows:
$ ('Input: radio [name = sex] ') [0]. checked = true;
3. Select the radio button (Female ).
Copy codeThe Code is as follows:
$ ('Input: radio [name = sex]: nth (1) '). attr ('checked', true );
Or
$ ('Input: radio [name = sex] ') [1]. checked = true;
4. Select the radio button (Unknown ).
Copy codeThe Code is as follows:
$ ('Input: radio [name = sex]: nth (2) '). attr ('checked', true );
Or
$ ('Input: radio [name = sex] ') [2]. checked = true;
5. Reset the radio button.
Copy codeThe Code is as follows:
$ ('Input: radio [name = sex] '). attr ('checked', false );