使用 JQuery 检查第一个单选按钮第一个、单选、按钮、JQuery

2023-09-06 19:20:10 作者:[无名指的等待]

我想检查每个组的第一个单选按钮.但是有一些单选按钮被禁用,所以脚本应该忽略它们并转到下一个非禁用按钮.

I would like to check the first radio button of each group. But there are some radio button that are disabled, so the script should ignore them and go to next non-disabled button.

我写了这样的东西,但它不起作用:

I wrote something like this but it doesn't work:

$(document).ready(function(){
if ($("input['radio']).is(':disabled'))
    {  
        $(this).attr('checked', false );
    }
else
    {
        $(this).attr('checked', true );
    }
});

非常感谢

推荐答案

如果您的按钮按名称属性分组,请尝试:

If your buttons are grouped by their name attribute, try:

$("input:radio[name=groupName][disabled=false]:first").attr('checked', true);

如果它们按父容器分组,则:

If they are grouped by a parent container, then:

$("#parentId input:radio[disabled=false]:first").attr('checked', true);
 
精彩推荐
图片推荐