题解 | #购物面板#
购物面板
https://www.nowcoder.com/practice/1448469386f746f5941db2712372f373
<script type="text/javascript">
// 补全代码
// 更新价格
function updatePrice(){
const zjNumber = document.querySelector("#zjsl").innerText;
const klNumber = document.querySelector("#klsl").innerText;
document.querySelector("#total").innerText = zjNumber * 28 + klNumber * 5
}
// 数量变更
function numberChange(type, action){
switch(type){
// 炸鸡操作
case 'zj':
const zjDom = document.querySelector("#zjsl");
const zjNum = parseInt(zjDom.innerText);
if(action === 'decrement'){
if(zjNum === 0) return
zjDom.innerText = zjNum - 1;
}else{
zjDom.innerText = zjNum + 1;
}
updatePrice()
break;
// 可乐操作
case 'kl':
const klDom = document.querySelector("#klsl");
const klNum = parseInt(klDom.innerText);
if(action === 'decrement'){
if(klNum === 0) return
klDom.innerText = klNum - 1;
}else{
klDom.innerText = klNum + 1;
}
updatePrice()
break;
}
}
</script>