使用 JQuery 检查第一个单选按钮 [英] Check first radio button with JQuery

查看:17
本文介绍了使用 JQuery 检查第一个单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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);

这篇关于使用 JQuery 检查第一个单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆