我想使用javascript获取选择框的值我有以下代码。
html部分
<select name="marked" id="marked" onchange="checkdata(this); ">
<option value="">SELECT</option>
<option value="all">ALL</option>
<option value="none">NONE</option>
<option value="read">READ</option>
<option value="unread">UNREAD</option>
</select>
脚本
<script type="text/javascript">
function checkdata()
{
for(var i=0; i < document.myform.message.length; i++)
{
document.myform.message[i].checked=true;
}
}
</script>
我尝试了代码
var all = document.myform.marked.options[document.myform.selectedIndex].value;
alert(all);
没有警报即将到来
我也试过
var all= document.getElementById('marked').value;
alert(all);
警告即将到来但是“1”
中每个选项的值答案 0 :(得分:3)
你错过了'.marked':
var all = document.myform.marked.options[document.myform.marked.selectedIndex].value;
alert(all);
答案 1 :(得分:2)
var e = document.getElementById("ctl00_cphContent_ddlVoteType");
var strOption = e.options[e.selectedIndex].value;
对我来说很好。请检查
答案 2 :(得分:1)
尝试
<form method="POST" name="me">
<select size="1" name="D1" onChange="checkData()">
<option value="99">Default</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>
<script Language="JavaScript"><!--
function checkData()
{
var myTest =
me.D1.options[me.D1.options.selectedIndex].value;
///or me.D1.options[me.D1.selectedIndex].value
alert(myTest);
}
</script>
答案 3 :(得分:1)
以下代码正在为我工作
Java脚本:
function checkdata()
{
alert(document.getElementById('marked').value);
}
HTML:
<select name="marked" id="marked" onchange="checkdata(this);">
<option value="">SELECT</option>
<option value="all">ALL</option>
<option value="none">NONE</option>
<option value="read">READ</option>
<option value="unread">UNREAD</option>
</select>
答案 4 :(得分:0)
获取所选值onchange
<script Language="JavaScript">
function checkdata(marked){
var marked_value = marked.value; // store the selected value marked_value
alert(marked_value); // do further processing with "marked_value" if needed
}
</script>
选项选择您不使用“已选中”用于收音机和复选框