
效果如上。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>变换色</title>
<script src="./jQuery/jquery-3.3.1.min.js"></script>
<style>
* {
margin: 0;
padding: 0;
}
.box {
position: absolute;
top: 40px;
right: 40px;
background: #9b59b6;
padding: 10px;
}
.box a {
display: block;
float: left;
height: 40px;
width: 40px;
/* margin: 10px; */
}
.box a:hover {
border: white 1px solid;
}
#blue {
background-color: #3498db;
}
#green {
background-color: #2ecc71;
}
#red {
background-color: #e74c3c;
}
#white {
background-color: #ecf0f1;
}
#orange {
background-color: #e67e22;
}
</style>
<script>
$(function() {
$('a').click(function() {
$('body').css('background-color', $(this).css('background-color'))
})
})
</script>
</head>
<body>
<div class="box">
<a href="#" id="red"></a>
<a href="#" id="green"></a>
<a href="#" id="orange"></a>
<a href="#" id="blue"></a>
<a href="#" id="white"></a>
</div>
</body>
</html>