Jquery 如果else条件在选中和未选中的情况下不起作用

Jquery 如果else条件在选中和未选中的情况下不起作用,jquery,Jquery,在我的jQuery代码中,当我点击第二个td时,它在一个tr中有一个输入,那么这个输入在我的代码中被检查,如果语句不执行它,那么执行else语句类似地,else语句也执行给出一个解决方案 $(function(){ $("table.confirmit-grid >tbody >tr >td:nth-child(3) input").prop("disabled",true); $("table.confirmit-grid >tbody >tr

在我的jQuery代码中,当我点击第二个td时,它在一个tr中有一个输入,那么这个输入在我的代码中被检查,如果语句不执行它,那么执行else语句类似地,else语句也执行给出一个解决方案

$(function(){
    $("table.confirmit-grid >tbody  >tr >td:nth-child(3) input").prop("disabled",true);
    $("table.confirmit-grid >tbody  >tr >td:nth-child(2)").click(function(){
        if($(this).find("input").is(":checked")) // this statement execute when input is unchecked
        {
            $(this).parent().find("td:nth-child(3) input").prop("disabled",false);
        }
        else //this statement execute when input is checked
        {
            $(this).parent().find("td:nth-child(3) input").prop("disabled",true);
            $(this).parent().find("td:nth-child(3) input").prop("checked",false);
        }
    });
});

我认为你的逻辑是相反的:

// this will be true if there are any checked boxes, so you need to negate it with a !
if($(this).find("input").is(":checked")) 
我想你想要

$(function(){
    $("table.confirmit-grid >tbody  >tr >td:nth-child(3) input").prop("disabled",true);
    $("table.confirmit-grid >tbody  >tr >td:nth-child(2)").click(function(){
        if(!$(this).find("input").is(":checked")) // this statement execute when input is unchecked
        {
            $(this).parent().find("td:nth-child(3) input").prop("disabled",false);
        }
        else //this statement execute when input is checked
        {
            $(this).parent().find("td:nth-child(3) input").prop("disabled",true);
            $(this).parent().find("td:nth-child(3) input").prop("checked",false);
        }
    });
});

//如果有任何复选框,这将是正确的

@Ehsan Sajjad我使用web应用程序,如果我们在firebug上使用此代码,它工作得很好,但是当我将其放到web上时,如果没有html,这将不起作用。没有人能弄清楚发生了什么。请尝试重新表述您的问题,您甚至看起来都没有在问问题使用正确的标点符号。就像帕特里克说的那样-你没有问题。请清楚地描述你打算看到的结果以及你正在观察的情况。我用带有标签和值的数据更新了答案,并使用标签生成了文本。我还添加了一个JSFIDLE示例;它工作得很好