<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
div {
width: 100%;
height: 50px;
border-radius: 10px;
text-align: center;
line-height: 50px;
}
</style>
</head>
<body>
<div>
<div>dafdafdsa</div>
</div>
<select id="sel" onchange="changecolor(this)">
<option value="white">1</option>
<option value="blue">2</option>
<option value="red">3</option>
<option value="yellow">4</soption>
</select>
</body>
<script>
function changecolor(me) {
document.div.style.backgroundColor = me[me.selectedIndex].value;
}
</script>
</html>
js原生实现点击option改变div颜色
最新推荐文章于 2024-05-02 20:30:37 发布