CodePudding user response:
<meta charset="UTF-8">
<style>
. Color> Div {
Height: 300 px;
width: 300px;
border-radius: 50%;
display: inline-block;
The line - height: 300 px;
text-align: center;
The font - size: 60 px;
cursor: pointer;
}
. Color> Div: NTH - of - type (1) {background - color: red}
. Color> Div: NTH - of - type (2) {background - color: green}
. Color> Div: NTH - of - type (3) {background - color: blue}
</style>
<body>
Window. The onl oad=function () {
Var color=0, 0;
Var colorlist=document. GetElementsByClassName (" color ") [0]. Children;
For (let id in colorlist) {
Colorlist [id]. Id=id;
Colorlist [id]. onm ousedown=function (e) {
Enclosing innerHTML=e.b utton===0? + + color [this id] : -- color [this. Id];//the left mouse button plus right minus
}
}
}
</script>