您的位置:首页 > Web前端 > HTML5

使用HTML5 select标签来实现更改网页背景颜色

2017-11-16 13:25 351 查看
<!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" onchange="load()"><!--在select selected的选项改变时触发事件-->
<option value="white">白色</option>
<option value="yellow">黄色</option>
<option value="green">绿色</option>
<option value="red">红色</option>
</select>
</body>

</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  HTML5select标签