Javascript 单击另一个
我试着改变单选按钮的状态,将其设置为,但没有成功。当我单击另一个单选按钮时,我需要更改选中的单选按钮。jQuery或javascript可用于此任务Javascript 单击另一个,javascript,jquery,html,Javascript,Jquery,Html,我试着改变单选按钮的状态,将其设置为,但没有成功。当我单击另一个单选按钮时,我需要更改选中的单选按钮。jQuery或javascript可用于此任务 <html> <body> <label for="0"> <select id="sorting"> <option>0</option> <option>1</option>
<html>
<body>
<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">
</body>
</html>
const selects=document.querySelectorAllselect
selects.forEach select=>select.addEventListener“单击”,事件=>
事件
目标
.parentElement
.nextElementSibling.checked=true
0
1.
2.
0
1.
2.
0
1.
2.
const selects=document.querySelectorAllselect
selects.forEach select=>select.addEventListener“单击”,事件=>
事件
目标
.parentElement
.nextElementSibling.checked=true
0
1.
2.
0
1.
2.
0
1.
2.
使用JQuery,您只需
$("select").change(function () {
$(this).next('input[type=radio]').attr('checked', 'checked');
});
它的作用:如果任何select元素发生更改,它将查找radio类型的下一个输入并进行检查
注意:您需要从HTML中删除s
$select.changefunction{
$this.next'input[type=radio]'。attr'checked','checked';
};
0
1.
2.
0
1.
2.
0
1.
2.
使用JQuery,您只需
$("select").change(function () {
$(this).next('input[type=radio]').attr('checked', 'checked');
});
它的作用:如果任何select元素发生更改,它将查找radio类型的下一个输入并进行检查
注意:您需要从HTML中删除s
$select.changefunction{
$this.next'input[type=radio]'。attr'checked','checked';
};
0
1.
2.
0
1.
2.
0
1.
2.
添加到目前为止您在操作系统中尝试过的内容。这段代码就是我尝试过的内容。@Бццццццццццццц?我甚至不知道你要找的是什么。加上你到目前为止在操作系统中尝试过的东西。这段代码就是我尝试过的。@CharStyleццццццццццццц1094?我甚至不知道你在找什么。谢谢!我会用这个!非常感谢。我会用这个!