0

I have aform which has lots of radio button both visible and hidden. I need to get only the visible radio buttons and do some manipulations. I am trying the below code. But its not working. Can somebody please help me in this. One group has 4-5 radio buttons. I need to check any of the radio button in the group is checked or not. I have the code which does just the opposite. I need something like this

$(group).find(':radio:visible:not(:checked)').each(function() {...});

But this is giving some error.

I have a fiddle created. http://jsfiddle.net/jUQYr/45/

Actually I need to see if any of the radio button is checked or not. If nothing is selected it should display error and return false. If both the radio groups are selected it should return true. But the fiddle is acting just the opposite. I tried make the fiddle with the above code. But its not working correctly. Can somebody please correct the fiddle?

Thanks in advance..

4

2 回答 2

0

你试过这个:

$(group).find(":radio:visible").not(":checked")
于 2013-11-13T15:11:22.523 回答
0

这是你想要的吗?

$('button').click(function(){
    var returnVal = true;
    $.each($('.input-container:visible[data-validation=required]'), function (idx,group) {
        var checked = $(group).find(':radio:checked');            
        $(group).next('ul.innererrormessages').remove();
        if (!checked.length) {
            var title = $(this).attr('title');
            $(group).after('<ul class="innererrormessages"><li>'+title+'</li></ul>');
            returnVal = false;
        }
    });
    alert(returnVal);
});

小提琴:

http://jsfiddle.net/jUQYr/51/

详细说明:我更改了逻辑以执行您实际上想要执行的操作:对于每个可见组,查看是否选中了单选按钮。如果不是,则显示一个文本(现在在组标签上指定,而不是在单个单选按钮上)并返回 false。

于 2013-11-13T15:44:26.080 回答