JQuery removes spaces at the beginning and end of a string (implemented in multiple methods)

Source: Internet
Author: User

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 );

Related Article

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.