我目前正在制作匹配两个应用程序(点击正方形,找到匹配的图片) 我遇到了问题,它的一部分。禁用点击事件,因此某个方块无法点击直到它自行重置。我试过replaceWith,但与此问题是,一旦我运行该事件不会再次运行,即使我使用attr将id回来。我试过(),但似乎打破它。删除点击事件
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/ –