答案 0 :(得分:2)
const selects = document.querySelectorAll("select")
selects.forEach( (select) => select.addEventListener('click', (event) =>
event
.target
.parentElement
.nextElementSibling.checked = true
))

<label for="0">
<select id="sorting">
<option>0</option>
<option>1</option>
<option>2</option>
</select>
</label>
<input type="radio" name="gender" value="male" id="0" checked>
<label for="1">
<select id="sorting1">
<option>0</option>
<option>1</option>
<option>2</option>
</select>
</label>
<input type="radio" name="gender" value="female" id="1">
<label for="2">
<select id="sorting2">
<option>0</option>
<option>1</option>
<option>2</option>
</select>
</label>
<input type="radio" name="gender" value="other" id="2">
&#13;
答案 1 :(得分:1)
使用JQuery你可以做到
$("select").change(function () {
$(this).next('input[type=radio]').attr('checked', 'checked');
});
它的作用:如果更改了任何select
元素,它会找到radio类型的下一个输入并进行检查。
注意:您需要从HTML中删除
<label>
。
$("select").change(function () {
$(this).next('input[type=radio]').attr('checked', 'checked');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="sorting">
<option>0</optiacon>
<option>1</option>
<option>2</option>
</select>
<input type="radio" name="gender" value="male" id="0">
<select id="sorting1" name="gender">
<option>0</option>
<option>1</option>
<option>2</option>
</select>
<input type="radio" name="gender" value="female" id="1">
<select id="sorting2" name="gender">
<option>0</option>
<option>1</option>
<option>2</option>
</select>
<input type="radio" name="gender" value="other" id="2">