<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.wujiao{
display: inline-block;
width:100px;
height:100px;
background: url('timg1.png') no-repeat center;
background-size: cover;
}
.wujiao_active{
background: url('timg2.png') no-repeat center;
background-size: cover;
}
</style>
<script src="jquery-1.9.1.min.js"></script>
</head>
<body>
<div class="wujiaoCon">
<div class="wujiao"></div>
<div class="wujiao"></div>
<div class="wujiao"></div>
<div class="wujiao"></div>
<div class="wujiao"></div>
</div>
<script>
$(".wujiaoCon .wujiao").click(function(){
$(".wujiaoCon .wujiao").removeClass("wujiao_active");
$(".wujiaoCon .wujiao:lt("+($(this).index()+1)+")").addClass("wujiao_active")
})
</script>
</body>
</html>
转载于:https://www.cnblogs.com/liuhao-web/p/9216493.html