2012-01-10 91 views
3
$(function() { 
    $("#MyInputBox").keyup(function() { 
     var nextChk = $(this).next(":radio:checked").attr('id')); 
     alert(nextChk); 
    }); 
}); 

什么是正确的方式来说“获取被选中的下一个复选框的ID”我什至关闭?使用jQuery获取单选按钮ID

+1

你试过了吗? – Blazemonger 2012-01-10 14:20:45

+0

你在问关于DOM遍历,但你没有提供你的DOM。 – 2012-01-10 14:23:14

+0

@amnotiam:没有打扰提供一个DOM,因为它是一个通用的问题:)应该提到假设我想。 – JustAnotherDeveloper 2012-01-10 14:28:13

回答

6

假设您的无线输入都是兄弟姐妹,你需要使用.nextAll(),然后缩小的第一场比赛。

$(this).nextAll(":radio:checked:first").attr('id'); 

$(this).nextAll(":radio:checked").first().attr('id'); 

或者你可以在技术上使用.nextUntil().next()

$(this).nextUntil(":radio:checked").next().attr('id'); 

另外,我看到你问复选框,但您的代码使用:radio,所以我想我不知道你真正想要的是哪一个。

+1

完美地工作,欢呼。仍然习惯于jQuery。一旦我的时间限制结束,我会将其标记为已回答:) – JustAnotherDeveloper 2012-01-10 14:27:29

相关问题