<!doctype html>
<html>
<head>
<style>
</style>
<script>
function load(){
var test=document.getElementById("test");
document.body.style.backgroundColor=test.options[test.selectedIndex].value;
//获得select的selectedIndex属性来获得option的value值,设置body的backgroundColor属性
}
</script>
<meta charset="UTF-8">
</head>
<body>
<select id="test" οnchange="load()"><!--在select selected的选项改变时触发事件-->
<option value="white">白色</option>
<option value="yellow">黄色</option>
<option value="green">绿色</option>
<option value="red">红色</option>
</select>
</body>
</html>
使用HTML5 select标签来实现更改网页背景颜色
最新推荐文章于 2024-04-30 14:03:44 发布