javascript - 跳转到下一个未禁用的单选按钮
问题描述
我想知道是否可以移动到下一个单选按钮
这是我从Selecting next radio button from selected one中复制的简单小提琴
https://jsfiddle.net/5pn69jed/
$('.next').click(function() {
$("input[name=choice]:checked").next().next().click();
});
解决方案
您的代码停在Two
因为three
被禁用。Two.next().next() = 三,但是three.click() 没有任何作用,因为它被禁用了。
从三个中删除禁用,您会发现它工作正常。
您可以使用.nextAll("input:enabled").first()
查找下一个启用的输入
$('.next').click(function() {
$("input[name=choice]:checked").nextAll("input:enabled").first().click();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="radio" id="choise_1" name="choice" checked="checked" />
<label for="choise_1">One</label>
<input type="radio" id="choise_2" name="choice" />
<label for="choise_2">Two</label>
<input type="radio" id="choise_3" name="choice" disabled="disabled" />
<label for="choise_3">(Three)</label>
<input type="radio" id="choise_4" name="choice" />
<label for="choise_3">Four</label>
<button class="next">SELECT NEXT</button>
推荐阅读
- union - BOOL 和 WORD 的联合位映射
- ios - 尝试在颤振中使用 share_plus 包共享图片时,如何修复 Facebook ios 共享对话框崩溃?
- python - Tkinter 在运行 exe 版本的应用程序时导致黑页
- java - 无法将 maven lib 部署到 maven Central
- python - 是否可以将多个 matplotlib.pyplots 绘制到一个图中,以便它们都在 python 中重叠?
- python - Django Python 当前登录用户
- facebook - Facebook 的共享调试器中的“获取的 URL”和“规范的 URL”有什么区别?
- java - 在 android-Java 代码中使用 Google ASR 时,一旦提示可见,它就会一直显示“再试一次”,没有机会说话
- xamarin.forms - 通过动态列出问题和动态“输入类型”来创建“向导”UI
- flutter - 类似 iOS 13 模态全屏的 Flutter 过渡