我希望能够显示按钮#1、按钮#2 的点击次数,并显示按钮#1+按钮#2 的点击总和。到目前为止,我所能展示的只是总和。
HTML
<button id="1" onclick = "countCar('ferrari');">Button#1</button>
<a>Ferraris</a><span id="ferrariCount"></span>
<a id="showSum">SUM<span id="carCount"></span></a>
<button id="2" onclick = "countCar('toyota');">Button#2</button>
<a>Toyotas</a><span id="toyotaCount"></span>
Javascript
var carCount = 0;
var ferrariCount = 0;
var toyotaCount = 0;
function countCar(type)
{
carCount = carCount + 1;
document.getElementById('carCount').innerHTML = carCount;
ferrariCount = ferrariCount + 1;
toyotaCount = toyotaCount + 1;
if(type =='ferrari'){document.getElementById('ferrariCount').innerHTML = ferrariCount;
}else{
document.getElementById('toyotaCount').innerHTML = toyotaCount;}
};