# select和option
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
</head>
<body>
<select name="" id="select">
<option value="3">1</option>
<option value="4">2</option>
</select>
</body>
</html>
<script type="text/javascript">
var myselect=document.getElementById('select');
document.getElementById('select').onchange=function(){
console.log(this.value); // return '';
}
document.getElementById('select').onchange=function(){
console.log(this.options[this.options.selectedIndex].value)
console.log(this.options[this.options.selectedIndex].text)
}
</script>
经过测试,其实两种方法都可以,但是有人说第一种方法不行,不过用IE模拟低版本浏览器也没出现问题。
← H5的video和radio meta标签 →