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>

相关文章:

  • 2021-11-12
  • 2021-11-03
  • 2021-12-16
  • 2022-12-23
  • 2022-12-23
  • 2021-12-10
  • 2022-12-23
猜你喜欢
  • 2021-12-18
  • 2022-12-23
  • 2021-11-10
  • 2022-12-23
  • 2021-08-19
  • 2022-12-23
相关资源
相似解决方案