Jquery 如何使用具有输入值的选择器访问HTML元素';s属性?

Jquery 如何使用具有输入值的选择器访问HTML元素';s属性?,jquery,Jquery,例如,单击类为a-choice1的div时使用此jQuery函数 $('.a-choice1').click(function () { if ($(this).children('input').prop('value') == 0){ $(this).siblings().children('input[value=1]').addClass('highlight_selected_right'); } }); 要在以下html代码中访问值为1的输入元素:

例如,单击类为a-choice1的div时使用此jQuery函数

$('.a-choice1').click(function () {
    if ($(this).children('input').prop('value') == 0){
        $(this).siblings().children('input[value=1]').addClass('highlight_selected_right');
    }
});
要在以下html代码中访问值为1的输入元素:

<div class="answer-container">
    <div class="a-choice1">
        <input type="radio" name="qa1" value="0" />
        <label for="btn1"></label>
        <span>The</span>    
    </div>

    <div class="a-choice1">
        <input type="radio" name="qa1" value="0" />
        <label for="btn2"></label>
        <span>Albus</span>
    </div>

    <div class="a-choice1">
        <input type="radio" name="qa1" value="0" />
        <label for="btn3"></label>
        <span>Number</span>
    </div>

    <div class="a-choice1">
        <input type="radio" name="qa1" value="1" id="correct"/>
        <label for="btn4"></label>
        <span>Mr.</span>
    </div>
</div>

这个
阿不思
数
先生
我认为遍历函数排序的逻辑是正确的,但我怀疑选择器值“input[value=1]”的正确性

这里有类似的问题:

试试这个:

 $('.a-choice1').click(function () {
          $(this).find('input[value=1]').addClass('highlight_selected_right');
 });

应该可以,有什么问题吗?@undefined-我希望它在您单击值为0的选项时,在值为1的选项上应用highlight_selected_right类(将div涂成绿色)。这是一把小提琴:好吧,这就是你的小提琴所发生的事情。您正在使用哪个浏览器?
input[value=“1”]
是正确的,正如您所拥有的,但是如果在运行时修改“value”,它将不起作用,我已经创建了一个供您使用的小提琴:;要使这项工作正常,请参阅:检查我随答案一起添加的演示的可能副本。我希望小提琴中的代码会发生什么情况?您编写的是,向单选按钮添加一个css类,该类的值为1 rt。抱歉,只需一次编辑。现在查看演示。演示url已更改。再次单击上面的演示链接。