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