JavaScript——点击按钮使div变色

<html>

<head>

<metacharset="UTF-8">

<title>点击按钮使div变色</title>

<style>

div{

border:1px solid white;

width:200px;

height:200px;

background-color:#7f7f7f;

}

</style>

</head>

<body>

<divid="one"></div>

<inputtype="button"value=""id="red">

<inputtype="button"value=""id="orange">

<inputtype="button"value=""id="yellow">

<inputtype="button"value="绿"id="green">

<inputtype="button"value=""id="blue">

<inputtype="button"value=""id="indigo">

<inputtype="button"value=""id="purple">

<script>

var one =document.getElementById("one");

var red=decoment.getElementById("red");

var orange=decoment.getElementById("orange");

var yellow=decoment.getElementById("yellow");

var green=decoment.getElementById("green");

var blue=decoment.getElementById("blue");

var indigo=decoment.getElementById("indigo");

var purple=decoment.getElementById("purple");

red.οnclick=function(){

one.style="background-color:red";

};

orange.οnclick=function(){

one.style="background-color:orange";

};

yellow.οnclick=function(){

one.style="background-color:yellow";

};

green.οnclick=function(){

one.style="background-color:green";

};

blue.οnclick=function(){

one.style="background-color:blue";

};

indigo.οnclick=function(){

one.style="background-color:indigo";

};

purple.οnclick=function(){

one.style="background-color:purple";

};

</script>

</body>

</html>


版权声明:本文为Chenbaby_原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。