2010年10月27日星期三

[JS]javascript获取select的当前值(兼容 IE、Firefox,Opera, Chrome)

document.getElementById("select").options[document.getElementById("select").options.selectedIndex].value

例 子:
<script>
function check()
{
      var select = document.getElementById("select").options[document.getElementById("select").options.selectedIndex].value;
      alert(select);
}
</script>
 <select name="select" id="select">
<option value="test1" selected="selected">Test1</option>
<option value="test2">Test2</option>
</select>
<input type="button" value="我要试试" onclick="check()"/>

没有评论:

发表评论