javascript 如何实现自动选择select的option
假如有两组select,如何选择了id的option1后自动选择user的optionA。类推<selectname="id"id="id"><option>1</opt...
假如有两组select,如何选择了id的option1后自动选择user的optionA。类推
<select name="id" id="id">
<option>1</option>
<option>2</option>
</select>
<select name="user" id="user">
<option>A</option>
<option>B</option>
</select> 展开
<select name="id" id="id">
<option>1</option>
<option>2</option>
</select>
<select name="user" id="user">
<option>A</option>
<option>B</option>
</select> 展开
1个回答
展开全部
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>
RunJS 演示代码
</title>
<script>
onload = function () {
id.onchange = function () {
user.children[this.selectedIndex].selected = true;
}
}
</script>
</head>
<body>
<select name="id" id="id">
<option>
1
</option>
<option>
2
</option>
</select>
<select name="user" id="user">
<option>
A
</option>
<option>
B
</option>
</select>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询