html select 获取value值

  • Post author:
  • Post category:其他


<select  οnchange=”myFunction(event)”  id=”test”>

<option label=”北京” value=”BJ”></option>

<option label=”上海” value=”SH”></option>

<option label=”天津” value=”TJ”></option>

<option label=”广州” value=”GZ”></option>

<option label=”深圳” value=”SZ”></option>

<option label=”石家庄” value=”SHZ”></option>

</select>

<input class=”form-control” id=”myText” type=”text” value=”” style=”display: none;”>

<script type=”text/javascript”>

function myFunction(e){

var val =  document.getElementById(“myText”).value = e.target.value;

console.log(val);

}

</script>