您的位置:首页 > 其它

onclick事件改变元素的背景颜色

2017-12-30 16:32 776 查看
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>onclick事件</title>
<script type="text/javascript" src="$function.js"></script>
</head>
<body>
<button style="background:red">红</button>
<button style="background:yellow">黄</button>
<button style="background:green">绿</button>
<button style="background:blue">蓝</button>
<button style="background:purple">紫</button>

<div id="divid" style="width:500px;height:500px;background:black">

</div>
</body>

<script type="text/javascript">
var buttons = $imgs("button");
for(var i=0;i< buttons.length;i++){
buttons[i].onclick = function(){
$("divid").style.background = this.style.background;
}
}
</script>

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