admin管理员组文章数量:1388835
$(function () {
$("#MyInputBox").keyup(function () {
var nextChk = $(this).next(":radio:checked").attr('id'));
alert(nextChk);
});
});
What is the correct way to say "Get the ID of the next checkbox which is checked" Am I even close?
$(function () {
$("#MyInputBox").keyup(function () {
var nextChk = $(this).next(":radio:checked").attr('id'));
alert(nextChk);
});
});
What is the correct way to say "Get the ID of the next checkbox which is checked" Am I even close?
Share Improve this question edited Jan 10, 2012 at 14:26 Rory McCrossan 338k41 gold badges320 silver badges351 bronze badges asked Jan 10, 2012 at 14:19 JustAnotherDeveloperJustAnotherDeveloper 3,19911 gold badges40 silver badges70 bronze badges 3- You're asking about DOM traversal, but you're not providing your DOM. – user1106925 Commented Jan 10, 2012 at 14:23
- @amnotiam : Didn't bother providing a DOM as it's a generic question :) Should have mentioned the assumption I suppose. – JustAnotherDeveloper Commented Jan 10, 2012 at 14:28
-
@RawryLions: Well, no DOM traversal question is generic. Some people try to use
.next()
when the elements aren't actually siblings (like when they're nested in ancestors that are siblings). So it always depends on the actual markup. – user1106925 Commented Jan 10, 2012 at 14:29
1 Answer
Reset to default 6Assuming your radio inputs are all siblings, you'd need to use .nextAll()
, and then narrow down to the first match.
$(this).nextAll(":radio:checked:first").attr('id');
or
$(this).nextAll(":radio:checked").first().attr('id');
Or you could technically use .nextUntil()
with .next()
.
$(this).nextUntil(":radio:checked").next().attr('id');
Also, I see that you're asking about checkboxes, but your code uses :radio
, so I guess I don't know which one you actually want.
本文标签: javascriptGetting a radio button ID with jQueryStack Overflow
版权声明:本文标题:javascript - Getting a radio button ID with jQuery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744627934a2616369.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论