1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| <script>
// total.value 是一个字符串"1"
let total = document.querySelector('#total');
let add = document.querySelector('#add');
let reduce = document.querySelector('#reduce');
// 点击add,事件监听
add.addEventListener('click', function() {
reduce.disabled = false;
// 递增递减隐式转换为number
total.value++
})
// 点击reduce,事件监听
reduce.addEventListener('click', function() {
total.value--
if (total.value <= 1) {
reduce.disabled = true;
}
})
</script>
|