首页 > 代码库 > javascript获取select 的id与值
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 = http://www.mamicode.com/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>
javascript获取select 的id与值