我有两个单选按钮:
<p>
<label for="input_1">Path to Excellent </label>
<input id="input_1" name="radio" type="radio" value="1" />
</p>
<p>
<label for="input_2">Award of Excellence</label>
<input id="input_2" name="radio" type="radio" value="2" />
</p>
我想使用其中一个的 id 获取 val():通过 jQuery 的“input_1”或“input_2”,如下所示:
$('input[#input_1,#input_2]:checked').val();
我的目标是从通过 id 检查的其中一个中获取 val() 。我怎样才能做到这一点?
最佳答案
您可以查看 starts在本例中,id
的值:
$("input[id^='input_']:checked").val();
关于javascript - 如何使用 jQuery 通过 id 选择多个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40663898/