使用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>
<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>
相关文章推荐
- JS实现网页背景颜色与select框中颜色同时变化的方法
- JS实现网页背景颜色与select框中的颜色同时变化
- JavaScript实现更改网页背景与字体颜色的方法
- JS实现网页背景颜色与select框中颜色同时变化的方法
- JavaScript实现更改网页背景与字体颜色的方法
- CSS实现网页背景颜色渐变的效果(火狐浏览器,IE,)
- 【JavaScript】轻松更改网页背景与字体的颜色
- jquery修改网页背景颜色通过css方法实现
- 用a伪类的后代标签实现鼠标放到图片上产生背景颜色变化
- JS实现鼠标滑过链接改变网页背景颜色的方法
- HTML5 Select标签基本使用
- HTML5使用Div标签来实现表格
- 更改系统的窗口颜色后,网页的背景不能显示
- 网页实现鼠标经过文字后更改颜色
- 【实例】html5中使用localStorage实现简易的便利贴网页
- css 选择后更改文字背景 CSS3 实现改变默认文本选中的颜色
- CSS实现网页背景颜色渐变的效果。
- 在IE6系列等老式浏览器中使用HTML5的新标签实现方案
- C#实现更改MDI窗体背景颜色的方法
- 如何使用css实现背景颜色渐变