昨夜からこの問題を解決しようとしてきましたが、まだうまくいきません。私はこれでひどく助けが必要です。状況は次のとおりです。クリック可能な画像が 4 つあり、それぞれの html ファイルに clickCount テキストボックスがあります。clickCount テキストボックスには、画像がクリックされた回数が表示されます。最初の 2 つの画像が機能するようになりましたが、3 番目の画像をクリックすると、2 番目の画像の clickCount テキストボックスが増加します。これが私のコードです:
<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>