题解 | #购物面板#
购物面板
https://www.nowcoder.com/practice/1448469386f746f5941db2712372f373
<script type="text/javascript">
// 补全代码
let zjAdd = document.querySelector("#zjtaishaola");
let zjSub = document.querySelector("#zjtaiduola");
let klAdd = document.querySelector("#kltaishaola");
let klSub = document.querySelector("#kltaiduola");
let zjCount = document.querySelector("#zjsl");
let klCount = document.querySelector("#klsl");
let totalAll = document.querySelector("#total");
zjAdd.onclick = () => {
// zjCount.innerText = parseInt(zjCount.innerText) + 1;
totalCount(zjAdd, zjCount, "add");
};
zjSub.onclick = () => {
totalCount(zjSub, zjCount);
};
klAdd.onclick = () => {
totalCount(klAdd, klCount, "add");
};
klSub.onclick = () => {
totalCount(klSub, klCount);
};
function totalCount(item, count, add) {
if (add) {
count.innerText = parseInt(count.innerText) + 1;
} else {
if (parseInt(count.innerText) > 0) {
count.innerText = parseInt(count.innerText) - 1;
}
}
totalAll.innerText =
28 * parseInt(zjCount.innerText) + 5 * parseInt(klCount.innerText);
}
</script>