Javascript 查找多个下拉列表的值时,仅检查第一个选项
这是我的密码:Javascript 查找多个下拉列表的值时,仅检查第一个选项,javascript,html,Javascript,Html,这是我的密码: <select id="gender" style="width: 125px;"> <option>Select</option> <option>Female</option> <option>Male</option> <option>Other</option></select> <select i
<select id="gender" style="width: 125px;">
<option>Select</option>
<option>Female</option>
<option>Male</option>
<option>Other</option></select>
<select id="car" style="width: 125px;">
<option id="2">Select</option>
<option id="2">Sport</option>
<option id="2">Luxury</option>
<option id="2">Muscle</option>
<option id="2">Formula 1</option></select>
它知道我有两个选择,但只检查第一个选择的第一个选项。因此,当我为每个选项选择第一个选项时,我得到:
女性
女性
而不是女性和运动。你为什么不直接像下面那样尝试呢
var gender=document.getElementById('gender').value;
var car=document.getElementById('car').value
它只会给你选择的值。你为什么不直接像下面那样尝试呢
var gender=document.getElementById('gender').value;
var car=document.getElementById('car').value
它只会给你选择的值。我不太明白。。。你想在性别变量中选择性别,在汽车变量中选择汽车吗?是的,我想知道两者的选择选项。我不太明白。。。您想在性别变量中选择性别,在汽车变量中选择汽车吗?是的,我想知道两者的选择选项。