开发者

How to know if radio is checked [duplicate]

This question already has answers here: 开发者_如何转开发 Closed 11 years ago.

Possible Duplicate:

Find out if radio button is checked with JQuery?

Hi, i want to make a div appear with jquery when one of 3 radio buttons is pressed..

I have 3 radio buttons, image video and sound, when the user clicks image, a div will appear.

how can i use jquery for this. I know how to do the div appearing part, just not the checking if the specific radio button is checked.

Bascially, how do i check if a specific radio is checked.

Thanks


if($('#radioButton').is(':checked')){
    //radio button with id 'radioButton' is selected
    //your logic here
} else {
   //radio button is not selected
   //your logic here
}


You can use

$('#radioButton').get(0).checked


if($('#radioButton1').attr('checked')) {
    // show div 1, hide div 2 and div 3
} else {
    if($('#radioButton2').attr('checked')) {
        // show div 2, hide div 1 and div 3
    } else {
        if($('#radioButton3').attr('checked')) {
            // show div 3, hide div 1 and div 2
        }
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜