gpt4 book ai didi

javascript - 读取选中的单选按钮,但不由检查触发

转载 作者:行者123 更新时间:2023-12-02 20:24:26 26 4
gpt4 key购买 nike

我有 2 个不同的单选按钮字段集 name=topname=bottom

<div class="branch">
<div class="element">
<label for="top">top color:</label>
<input type="radio" value="1" name="top" checked="checked">black
<input type="radio" value="0" name="top">white
<input type="radio" value="null" name="top">transparent
</div>
<div class="element">
<label for="bottom">bottom color:</label>
<input type="radio" value="1" name="bottom">black
<input type="radio" value="0" name="bottom" checked="checked">white
<input type="radio" value="null" name="bottom">transparent
</div>
</div>

我知道如何在选择单选按钮时检测它的值,我引用 $(this)获取刚刚选择的值。我想做的是当单击不相关的按钮时触发读取。我单击另一个元素(不是单选按钮本身),此时我想读取检查了哪个值(黑色、白色、透明)name=topname=bottom 。我如何用 jquery 做到这一点?我没有引用$(this)不再了。我是否需要循环遍历每个输入类型单选选项并检查它是否已选中?我希望有人能提出更好的方法。在上面的示例中,我想读取顶部颜色的检查值为 1,底部颜色的检查值为 0

最佳答案

var topColor = $(".element input:checked").eq(0).val();

关于javascript - 读取选中的单选按钮,但不由检查触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5072415/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com