我有一个ASP.NET网站,在.aspx
页面中包含以下代码。
<form action="#" id="demoForm" class="demoForm">
<select id="SelectEquipmentDropdown">
<option value="1">1</option>
<option value="2">2</option>
</select>
</form>
当这在HTML中呈现时,我得到以下
<form action="#" id="demoForm" class="demoForm">
<select id="SelectEquipmentDropdown">
<option value="1">1</option>
<option value="2">2</option>
</select>
</form>
在我的HTML页面上,我看到了这个
当我使用此javascript返回选项的selectedValue
时,我得到值undefined
返回。有人可以告诉我我做错了吗???
var e = document.getElementById("SelectEquipmentDropdown");
var selectedEquipmentDropdown = e.options[e.selectedIndex].Value;
答案 0 :(得分:5)
.Value
应该.value
看小提琴https://jsfiddle.net/Lddyn573/9/
<form action="#" id="demoForm" class="demoForm">
<select id="SelectEquipmentDropdown" onchange="myFunction()">
<option value="1">1</option>
<option value="2">2</option>
</select>
</form>
<script>
function myFunction(){
var e = document.getElementById("SelectEquipmentDropdown");
var selectedEquipmentDropdown = e.options[e.selectedIndex].value;//change it here
alert(selectedEquipmentDropdown);
}
</script>