<!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>Document</title>
<style>
ul{
margin: 0;
padding: 0;
list-style: none;
}
li{
float: left;
width: 30px;
height: 30px;
border: 1px #000 solid;
margin-right: 3px;
border-radius: 50%;
}
</style>
</head>
<body>
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
<script src="jquery-1.10.1.min.js"></script>
<script>
$("li").on("click",function (){
$("li").css("backgroundColor","white");
$(this).css("backgroundColor","red").prevAll().css("backgroundColor","red"); //自己的背景颜色变成红色,且他之前的所有兄弟元素也变成红色
})
</script>
</body>
</html>
练习-好评系统
最新推荐文章于 2024-05-07 01:36:41 发布