-
Notifications
You must be signed in to change notification settings - Fork 0
/
10_index.html
54 lines (52 loc) · 1.2 KB
/
10_index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
.score {
list-style: none;
margin: 0;
padding: 0;
}
.score li {
display: inline-block;
width: 50px;
height: 50px;
border: 1px solid #f00;
border-radius: 50%;
cursor: pointer;
}
</style>
</head>
<body>
<h3>请打分</h3>
<ul class="score">
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
<script src="js/jquery-1.11.3.js"></script>
<script>
//获得当前单击的li在所有li中的位置i,i及其执行的都变为红色,i之后的都变为白色
// $("ul.score")
// .on("click","li",function(){
// var $li=$(this);
// //在所有li中,找当前li的位置
// var i=//$("ul.score>li").index($li);
// $li.index();
// $(`ul.score>li:lt(${i+1})`)
// .css("background","red");
// $(`ul.score>li:gt(${i})`)
// .css("background","");
// })
$("ul.score").on("click","li",function(){
var i=$("ul>li").index(this)
$(`ul>li:lt(${i+1})`).css("background","red")
$(`ul>li:gt(${i})`).css("background","#fff")
})
</script>
</body>
</html>