我一直在试图解决这个问题,因为昨晚仍然没有运气。我非常需要帮助。情况如下:我有4个可点击的图片,每个图片在我的html文件上都有一个clickCount文本框。 clickCount文本框将显示图像被点击的次数。我得到了前2张图片,但是当我点击第三张图片时,第二张图片上的clickCount文本框会增加。这是我的代码:JQuery if else语句在第二种情况下停止
<script>
var targetId="";
$(".foods").click(function(event) {
if (event.target.id=="img1"){
targetId="img1clickCount";
addOrders();}
else if(event.target.id="img2"){
targetId="img2clickCount";
addOrders(); }
else if(event.target.id="img3"){
targetId="img3clickCount";
addOrders(); }
else if(event.target.id="img4"){
targetId="img4clickCount";
addOrders(); }
}); });
function addOrders(){
document.getElementById(targetId).value=parseInt(document.getElementById(targetId).
value)+1;
}
</script>
<body>
<table cellpadding=0 cellspacing=0 border=1 height=330 style="margin-left:18px">
<tr>
//Images
<td><img src="gangjeong.png" width="100" style="cursor:pointer" id="img1"
class="foods"></td>
<td><img src="daktoritang.png" width="100" style="cursor:pointer" id="img2"
class="foods"></td>
<td><img src="tangsuyuk.png" width="100" style="cursor:pointer" id="img3"
class="foods"></td>
<td><img src="tangsuyuk.png" width="100" style="cursor:pointer" id="img4"
class="foods"></td>
<tr height="5">
//Textboxes
<td><input type="text" maxlength="5" readonly="readonly" value="0" id="img1clickCount">
</td>
<td><input type="text" maxlength="5" readonly="readonly" value="0" id="img2clickCount">
</td>
<td><input type="text" maxlength="5" readonly="readonly" value="0" id="img3clickCount">
</td>
<td><input type="text" maxlength="5" readonly="readonly" value="0" id="img4clickCount">
</td>
</tr></table>
哦,我是多么白痴啊。非常感谢您的快速回复。现在正在工作。干杯! – Clyde