HTML Tag operation Accumulation

Source: Internet
Author: User

1. Select tag
(1) event onchange triggered when the index changes
(2) obtain the selected text in the SELECT statement:
$ ("# XXX"). Find ("option: Selected"). Text ();
(3) obtain the selected value of select:
$ ("# XXX"). Val ();
(4) set the index selected by the SELECT statement:
$ ("# Ddlregtype"). Get (0). selectedindex;
(5) set the selected value of select:
$ ("# Ddlregtype"). ATTR ("value", "normal");
$ ("# Ddlregtype"). Val ("normal ");
$ ("# Ddlregtype"). Get (0). value = value;

2. Input checkbox tag

Upload: <input id = "CHK1" name = "Chk" type = "checkbox" value = "1"/>
Preview: <input id = "CHK2" name = "Chk" type = "checkbox" value = "2"/>
Outgoing mail: <input id = "chk3" name = "Chk" type = "checkbox" value = "4"/>
Download: <input id = "chk4" name = "Chk" type = "checkbox" value = "8"/>

(1) set the default option:
$ ("# Chkupload"). ATTR ("checked", true );

(2) Select All
$ ("[Name = chk]: checkbox"). ATTR ("checked", true );

(3) invert Selection
$ ("[Name = chk]: checkbox"). Each (function (){
$ (This). ATTR ("checked ",! $ (This). ATTR ("checked "));
});

(4) obtain the selected value (multiple options ):
VaR STR = "";
// Cyclically selected checkbox
$ ('Input [name = "Chk"]: checked'). Each (function (){
STR + = $ (this). Val ();
});
Alert (STR );

(5) Determine whether the specified selection box is selected

$ ("# CHK1"). ATTR ("checked"); the returned value is true, not false.

3. Input Radio (single choice)

<Input id = "radio1" name = "R1" type = "radio" value = "1"/>
<Input id = "Radio2" name = "R1" type = "radio" value = "0"/>

(1) obtain the selected value

  $('input[name="R1"]:checked').val();

(2) Obtain a specific radio value, such as the second one:

  $('input[name="R1"]:eq(1)').val();

(3) traversal, same as the checkbox tag;

(4) assign values to select

$ ('Input [name = "R1"] [value = "1"] '). ATTR ("checked", true );

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.