<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN">
<head>
<title>tab 改变颜色</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
#div1 {
width: 200px;
height: 200px;
background: yellow;
}
</style>
<script>
//第一种方法
// function toBlue(){
// var odiv = document.getElementById('div1');
// odiv.style.background='blue';
// }
// function toGreen(){
// var odiv = document.getElementById('div1');
// odiv.style.background='green';
// }
// function toOrange(){
// var odiv = document.getElementById('div1');
// odiv.style.background='orange';
// }
//第二种方法 传参
function toChange(color){
var odiv = document.getElementById('div1');
odiv.style.background=color;
}
</script>
</head>
<body>
<input type="button" value="变蓝" οnclick="toChange('blue');"/>
<input type="button" value="变绿" οnclick="toChange('green');"/>
<input type="button" value="变黄" οnclick="toChange('yelloe');"/>
<div id="div1"></div>
</body>
</html>
javascript 切换按钮改变div颜色
最新推荐文章于 2023-04-14 10:35:45 发布