【发布时间】:2017-09-26 00:20:49
【问题描述】:
enter image description here我正在尝试检索最终用户在下拉列表中选择的值。变量 country 始终为 null,我使用下拉列表的 id 来检索用户选择的值。
这是我认为的代码:
<script>
var country = document.getElementById("Countries");
var value = country.options[country.selectedIndex].value;
var text = country.options[country.selectedIndex].text;
</script>
@Html.Label("Country", "Country")
<select name="Countries" id="Countries">
@foreach (var country in ViewBag.countries)
{
<option value="@(country.country)">@(country.country)</option>
}
</select>
}
【问题讨论】:
标签: javascript asp.net drop-down-menu