开发者

finding the value of radio button with jquery

开发者 https://www.devze.com 2022-12-29 06:56 出处:网络
i have this code below to show different divs when i choose certain radio buttons: if ($(\"input[@name=\'exerciseRB\']:checked\").val() == \'New\') {

i have this code below to show different divs when i choose certain radio buttons:

if ($("input[@name='exerciseRB']:checked").val() == 'New') {
    $("#newExercise").show();
    $("#existingExercise").hide();
 }
 else {
    开发者_C百科$("#newExercise").hide();
    $("#existingExercise").show();
 } 

at first, i just had two radio buttons (both named exerciseRB and everything works fine.

Now, later in my web page i added two new radio buttons (with the name lessonRB).

The issue is that once i added these other new radio buttons when i look up this in firebug:

$("input[@name='exerciseRB']:checked")

i actually get an array back with both the exerciseRB item as well as the lessonRB item. Its almost as if the

 @name='exerciseRB'

is being ignored. any ideas here?


You don't need the @ before name in your selector.


@name='exerciseRB' should be name=exerciseRB ie:

$("input[name=exerciseRB]:checked")
0

精彩评论

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

关注公众号