原生javascript中的select的简单实例
作者:
AMONTOP | 来源:发表于
2019-02-13 14:31 被阅读0次<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<select id="item" onchange="sclick()">
<option value="1">aa</option>
<option value="2">bb</option>
<option value="3">cc</option>
</select>
<input type="text" value="通过" id="mytext">
<script>
function sclick() {
let obj = document.getElementById("item");
var index = obj.selectedIndex;
let options2 = obj.options[index].text;
console.log(options2);
var text = document.getElementById("mytext");
if(options2 == "aa" || options2 == "bb"){
text.value = "通过";
}else if(options2 == "cc"){
text.value = "不合格"
}
}
</script>
</body>
</html>
本文标题:原生javascript中的select的简单实例
本文链接:https://www.haomeiwen.com/subject/zlcdeqtx.html
网友评论