現在、マッチ2アプリを作成中です(マッチする画像を見つけてください) 私は1つの部分で問題が発生しています。クリックイベントを無効にすると、特定の四角形をクリックしてリセットするまでクリックできなくなります。私はreplaceWithを試してみましたが、その問題は一度実行すると、attrを使用してもイベントが再度実行されないことです。私は試しましたが、それはちょうどそれを破るようです。クリックイベントを削除する
HTMLスニペット:
<table border="1">
<tr>
<td id="" colspan="3">Lifes Remaining:</td>
<td id="lives"></td>
</tr>
<tr id="1to4">
<td class="a1" id="a1">0</td>
<td class="a2" id="a2">0</td>
<td class="a3" id="a3">0</td>
<td class="a4" id="a4">0</td>
</tr>
<tr>
<td colspan="4"><input type="button" id="press" value="Press" /></td>
</tr>
</table>
コードスニペット:
var set1a = 1, set1b = 1, set2a = 2, set2b = 2;
var rand1 = 0;
var rand2 = 0;
var lives;
var savedData1 = "", savedData2 = "";
var check1 = "", check2 = "";
var idCheck1 = "", idCheck2 = "";
$(document).ready(function()
{
$("#lives").text("");
$("#press").click(function()
{
lives = 3;
$("#lives").text(lives);
for(var i = 1; i < 5; i++)
{$("#a"+i).text("0").css('color', 'black');}
i = 0;
<!-----------------Set Position--------------------------------->
do{rand1 = 1 + Math.floor(Math.random() * 4);}
while($("#a"+rand1).text() != 0)
$("#a"+rand1).text(set1a);
do{rand2 = 1 + Math.floor(Math.random() * 4);}
while($("#a"+rand2).text() != 0)
$("#a"+rand2).text(set1b);
do{rand1 = 1 + Math.floor(Math.random() * 4);}
while($("#a"+rand1).text() != 0)
$("#a"+rand1).text(set2a);
do{rand2 = 1 + Math.floor(Math.random() * 4);}
while($("#a"+rand2).text() != 0)
$("#a"+rand2).text(set2b);
<!-----------------Set Position--------------------------------->
});
$("#a1").click(function()
{
$(".a1").css('color', 'lightgreen');
if(check1 == "")
check1 = $("#a1").text();
else
check2 = $("#a1").text();
if(idCheck1 == "")
idCheck1 = "#a1";
else
idCheck2 = "#a1"
if(check1 && check2 != "")
{
if(check1 != check2)
{
$(".a1").css('color', 'black');
}
}
});
$("#a2").click(function()
{
$(".a1").css('color', 'lightgreen');
check1 = '1';
if(idCheck1 == "")
{
idCheck1 = "#a1";
}
else
idCheck2 = "#a1"
if(check1 && check2 != "")
{
$(".a1").css('color', 'black');
}
});
$("#a3").click(function()
{
});
$("#a4").click(function()
{
});
});
私は私はある数のクリック機能を無効にすることができます#A1-4クリック機能で使用するものが必要別の番号がタップされるまでタップしてから再び有効にします。
$("#a1").click(function()
{
if(check1 == "")
check1 = $("#a1").text();
else
check2 = $("#a1").text();
if(idCheck1 == "")
idCheck1 = "#a1";
else
idCheck2 = "#a1"
*Disable #a1 click function*
if(check1 && check2 != "")
{
if(check1 != check2)
{
$(".a1").css('color', 'black');
*Enable #a1 click function*
}
}
});
すべてのヘルプなどの
が何かがappricated、あなたが任意の明確化が必要な場合、私はクリックイベントリスナーを削除します
マイク
あなたはアンバインドしようとしたバインド http://api.jquery.com/unbind/ http://api.jquery.com/bind/ています –