Home  >  Article  >  Web Front-end  >  JQuery determines whether the radio (radio button) is selected and summarizes the method of obtaining the selected value_jquery

JQuery determines whether the radio (radio button) is selected and summarizes the method of obtaining the selected value_jquery

WBOY
WBOYOriginal
2016-05-16 16:03:576651browse

1. Determine the selection by obtaining the selected value

Upload the code directly, don’t forget to quote the JQuery package

Copy code The code is as follows:





JQuery radio






Male
Female


Very satisfied
Satisfied
Not satisfied
Very Bad







Radio cannot be judged by "checked" equality, it can only be judged by true


Copy code The code is as follows:







2. Use the checked attribute to determine the selection

Radio cannot be judged by "checked" equality, it can only be judged by true

Copy code The code is as follows:







3. jquery gets the value of the radio button

Copy code The code is as follows:

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

Another: Determine whether the radio is selected and get the selected value

As shown below:
Copy code The code is as follows:

function checkradio(){
var item = $(":radio:checked");
var len=item.length;
if(len>0){
alert("yes--the selected value is:" $(":radio:checked").val());
}
}

4. Get the value of a set of radio selected items

Copy code The code is as follows:

var item = $('input[name=items][checked]').val();

5. Set the radio button to be selected

Copy code The code is as follows:

$("input[type=radio]").attr("checked",'2');//Set the item with value=2 as the currently selected item
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn