我一直在挣扎这个,请你能帮助吗?这里是代码。我想组按钮工作相互独立。例如,如果我按下主页按钮,计数不应该转移到客人按钮。它应该从零开始时,单击,但它计数什么已经存储在变量之前,它被单击。
const homeScreen = document.getElementById("home-screen");
const guestScreen = document.getElementById("guest-screen");
let count = 0;
homeScreen.textContent = 0;
guestScreen.textContent = 0;
const plusOne = () => {
count += 1;
guestScreen.textContent = count;
}
const plusTwo = () => {
count += 2;
guestScreen.textContent = count;
}
const plusThree = () => {
count += 3;
let result = guestScreen.textContent = count;
if (result.length !== 0) {
return result;
}
}
const reset = () => {
guestScreen.textContent = 0;
}
const homeOne = () => {
count += 1;
homeScreen.textContent = count;
console.log("Clicked Home");
}
<div class="container">
<div class="d-flex justify-content-between bd-highlight mb-2">
<div id="left">
<h3 class="home">HOME</h3>
<span id="home-screen" class="float-start rounded"></span>
<div>
<button onclick="homeOne()" class="btn btn-info">+1</button>
<button onclick="homeTwo()" class="btn btn-info">+1</button>
<button onclick="homeThree()" class="btn btn-info">+1</button>
</div>
</div>
<div><Button onclick="reset()" class="btn reset">Reset</Button> </div>
<div id="left">
<h3 class="text">GUEST</h3>
<span id="guest-screen" class="float-end rounded"></span>
<div>
<button onclick="plusOne()" class="btn ">+1</button>
<button onclick="plusTwo()" class="btn ">+1</button>
<button onclick="plusThree()" class="btn ">+1</button>
</div>
</div>
</div>
<div class="row">
<div class="row">
<div class="row">
<div class="col-sm-4">
</div>
<div class="row">
<div class="col-sm-5">
</div>
</div>
</div>
</div>
</div>
</div>
1条答案
按热度按时间zyfwsgd61#
然后使用两个不同变量:
homeCount
和guestCount
。