删除点击事件

时间:2017-02-27 08:33:41

标签: jquery event-handling click

我正在制作一个Match Two应用程序(点击正方形,找到匹配的图片) 我有1部分问题。禁用click事件,以便在重置自身之前无法单击某个方块。我已经尝试过replaceWith,但问题是,一旦我运行该事件不会再次运行,即使我使用attr将id重新放入。我已经尝试过off()但这似乎打破了它。

HTML代码段:

fsize_survive_cross = pd.crosstab(full[0:890]['Fsize'], full[0:890]['Survived'])
fsize_survive_cross.plot(kind='bar',title='Survival Rate by Family Size')

代码段:

<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>

我需要在#a1-4点击功能中使用一些功能,这些功能允许我禁用点击的数字的点击功能,直到点击另一个号码,然后重新启用它。

这样的东西
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()
        {

        });     
    });

任何帮助都会被批评,如果您需要任何澄清,请告诉我

麦克

1 个答案:

答案 0 :(得分:1)