forked from Chuyue0/javascript-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjs_priceIncrease.html
54 lines (47 loc) · 1.46 KB
/
js_priceIncrease.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 lang="en">
<head>
<meta charset="utf-8">
<title>价格增减</title>
</head>
<script type="text/javascript" src="jquery-1.12.0.min.js"></script>
<script type="text/javascript">
$(function() {
var shu=$('.shu'),
jia=$('.jia'),
add=$('.add'),
min=$('.min'),
n=1;
$(add).click(function(event) {
if(n<2 && $(this).hasClass('min')){
n=1;
}else if($(this).hasClass('add')){
n++;
}else if($(this).hasClass('min')){
n--;
}
shu.text(n)
jia.text(n*100)
});
$(min).click(function(event) {
n--;
shu.text(n);
if(n<2){
n=1
$(shu).text('1')
}
jia.text(n*100)
});
});
</script>
<body>
<!-- 数量加减 -->
<div class="consoleButton">
<button class="add">+</button>
<button class="min">-</button>
</div>
<!-- 价格加减 -->
<span class="shu">1</span>
<span class="jia">100</span>
</body>
</html>