Operations on server controls DropdownList, RadioButtonList, and CheckboxList in JQuery

Source: Internet
Author: User

I. DropDownList
Bytes -------------------------------------------------------------------------------------------
When JQuery is used for traversal,
$ ("Input"). each (function (I ){
......
}
When the operation object type is dropdownlist: (Note: The DropDownList type in firefox is "select-one ")
Get the selected value: $ (this). val (); (if it is not a traversal operation, $ (this) is replaced with $ ('# Control Id '))
Get the selected text: $ (this ). find ("option: selected "). text (); or $ ("# Control name option: selected "). text ();
Obtain the selected index: $ (this). get (0). selectedIndex;
Ii. RadioButtonList
Bytes -------------------------------------------------------------------------------------------
If there is only one RadioButtonList on the page, you can use $ ("input [type = 'Radio ']: checked"). val () to obtain the selected value.
If there are two or more radiobuttonlists on the page:
Step 1: Obtain the Id of the RadioButtonList control and set var objId = Control Id;
Step 2: Obtain the control Name and set var radioName = $ ("input [id ^ = '" + objId + "']"). eq (0 ). attr ('name ');
Step 3: Values
Get the selected value: $ ("input [name = '" + radioName + "']: checked"). val ());
Get the selected text: $ ("input [name = '" + radioName + "']: checked + label"). text ());

Iii. CheckBoxList
Bytes -------------------------------------------------------------------------------------------
Determines whether a selected method exists. The objId is the Id of the CheckBoxList.
Currently, js cannot be used to directly obtain the value of the server control CheckBoxList. It can only be achieved through some tips, such as adding additional attributes.
In the code, selectedText is used to obtain the selected text value, and selectedValue is used to obtain the selected value.
Copy codeThe Code is as follows:
Function hasCheckedByCheckbox (objId ){
Var checkedCount = 0;
$ ("Input [id ^ = '" + objId + "']"). each (function (){
// Var checkName = $ (this). attr ('name ');
// Var selectedText = $ ("input [name = '" + checkName + "']: checked + label"). text ();
// Var selectedValue = $ (this ). parent ('span '). attr ('alt'); // use hack to obtain the value selected in checkboxList using js. You need to add an additional attribute alt in <asp: ListItem
If ($ (this). attr ('checked ')){
CheckedCount ++;
}
});
Return checkedCount> 0;
}

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.