Sample Code of JQuery to determine whether radio is selected and obtain the selected value, jqueryradio
Other radio operations will be added later. Directly upload the code. Do not forget to reference the JQuery package.
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Comments: var boolCheck = $ ('input: radio [name = "sex"] '). is (": checked"); better, this method is more concise
Is () Checks Matching Element Sets Based on selectors, elements, or jQuery objects. if at least one element matches a given parameter, true is returned.
If garbled characters are stored, we recommend using notepad ++.
Check whether jquery radio is selected
Are you a single radio or multiple radio (for example, judge whether one of the two radio S is selected )?
For example, the Code is as follows:
//////////////////////////////////////// ///////// Script code ///////////////////////// //////////////////////////////
Var val = $ ('input: radio [name = "sex"]: checked'). val (); // obtain the value selected from the object whose name is sex.
If (val = null) {// null indicates that no item is selected.
Alert ("Nothing selected! ");
Return false;
}
Else {// otherwise, the value of the selected item is output (male or female)
Alert (val );
}
//////////////////////////////////////// ////// Code related to some pages ///////////////////////////// ///////////////////
<Input type = "radio" name = "sex" value = "male"/> male
<Input type = "radio" name = "sex... the remaining full text>
How does jquery determine whether radio is selected?
$ (": Radio"). each (function (){
If ($ (this). attr ("checked ")){
Alert ("selected ");
} Else {
Alert ("not selected ");
}
})