我想這個功能打印球圖片的數量或消防車的圖片在用戶點擊數:試圖爲特定圖像類型追加圖像計數| jQuery的
function imageCounter(){
var ballCount = 0;
var truckCount = 0;
$('img[src*=ball]').each(function(){
if($(this).prop("checked")){
ballCount+=1;
}
$('#radioButtons').append("There are " + ballCount + " ball images.");
});
$('img[src*=truck]').each(function(){
if($(this).prop("checked")){
truckCount+=1;
}
$('#radioButtons').append("There are " + truckCount + " truck images.");
});
}
我覺得我接近..
我有4個球圖像,和1輛救火車圖像。我的代碼目前不給我圖像的數字值,而是打印輸出消息4次的球,1次的消防員。
有關從哪裏出發的建議?
這是非常多的。您也可以在底部打印出一條消息,或者在兩個循環之後再次使用變量做其他事情。 – Blizzardengle
這是有效的,現在它不是根據圖像的數量重複每個句子。但它也只是給我0的圖像數量,它根本不考慮我的計數器:/有什麼想法爲什麼? – MrJesus