javascript获取select 的id与值

javascript获取select 的id与值

<script type="text/javascript">
function showOptionId () {
var type = document.getElementById ("select"); //获取select
var typeId = type.options [type.selectedIndex].id; //获取option的ID
var typeValue = type.options [type.selectedIndex].innerText; //获取option的内容
alert ("ID:" +typeId + ", value:" + typeValue); //返回
}

</script>
<select id = "select" onchange = "showOptionId ()">
<option id = "id1" >海角孤星</option>
<option id = "id2" >http://www.jinyuanbao.cn</option>
<option id = "id3" >403033895</option>
<option id = "id4" >yangyan6032@126.com</option>
<option id = "id5" >warewolf</option>
</select>

posted @ 2014-10-16 16:31  jyb2014  阅读(1674)  评论(0编辑  收藏  举报