js怎么获取select的显示值

JavaScript012

js怎么获取select的显示值,第1张

var selectText = document.getElementById("sect").options[selectIndex].text //获得被选中的项目的文本,即显示值

<script>

var arr=[{"id":"28","url":"a.com","name":"A-站"},{"id":"22","url":"a.com","name":"B-站"}]

window.onload=function(){

   document.getElementById("id").onchange=function(){

      var v=this.value

      var a=arr.filter(function(o){return o.id==v})[0]

      document.getElementById("name").innerHTML="ID:"+a.id+"<br>URL:"+a.url+"<br>NAME:"+a.name

   }

}

</script>

<select name="id" id="id">

<option value="">选择线路</option>

<option value="28">线路1</option>

<option value="22">线路2</option>

</select>

<div id=name></div>