Nav*_*eva 1 javascript asp.net select getelementbyid
我知道这可能是一个非常简单的问题,我试图在网上找到解决方案,但我无法理解......我有以下C#/ ASPX代码:
SelectArea += "<select name=\"Area\" id=\"area\">" + "<option value=\"Default\" style=\"display:none;\">SELECT AREA</option>";
for (i = 0; i < ds.Tables[0].Rows.Count; i++)
{
AreaName = ds.Tables[0].Rows[i]["AreaName"].ToString();
SelectArea += string.Format("<option value=\"{0}\"/>{0}</option>", AreaName);
}
SelectArea += "</select>";
Run Code Online (Sandbox Code Playgroud)
这个javascript函数在提交后发生
function validateProfile() {
var el = document.getElementById("area").value;
alert(el);
}
Run Code Online (Sandbox Code Playgroud)
我想要一些如何获取列表中所选值的编号.我试过上面的代码,但它不起作用.
希望得到帮助,谢谢!
Emm*_*l N 10
例如,如果你有
<select id="myselect">
<option value="1">value1</option>
<option value="2" selected="selected">value2</option>
<option value="3">value3</option>
</select>
Run Code Online (Sandbox Code Playgroud)
要获得选择的选项,请执
var selects = document.getElementById("myselect");
var selectedValue = selects.options[selects.selectedIndex].value;// will gives u 2
var selectedText = selects.options[selects.selectedIndex].text;// gives u value2
Run Code Online (Sandbox Code Playgroud)
示例JsFiddle
| 归档时间: |
|
| 查看次数: |
42794 次 |
| 最近记录: |