JQuery嵌套条件

JQuery嵌套条件,jquery,nested,conditional-statements,Jquery,Nested,Conditional Statements,可以在JQuery中嵌套条件语句吗?下面的代码可以工作,如果我剥去了外部,但一旦我把它加回来,它就停止工作了。有人能告诉我这是否可能吗?我不想过分检查我的语法 $("input[title$='Derived']").click(function() { if ($("input[title$='Derived']").is(":checked")) { var r = confirm("This will clear the values of the Original

可以在JQuery中嵌套条件语句吗?下面的代码可以工作,如果我剥去了外部,但一旦我把它加回来,它就停止工作了。有人能告诉我这是否可能吗?我不想过分检查我的语法

$("input[title$='Derived']").click(function() {
    if ($("input[title$='Derived']").is(":checked")) {
        var r = confirm("This will clear the values of the Original Module and Amount Reused fields. Do you wish to continue?");
            if (r==true) {
                $('input[title="Original Module"]').val('');
                $('input[title="Amount Reused"]').val('');
                $("nobr:contains('Original Module')").closest('tr').toggle();
                $("nobr:contains('Amount Reused')").closest('tr').toggle();
            }
            else {
                alert("You pressed Cancel!");
            }
    else {
        alert("Test!");
    }
    });
作为旁注,警告(“您按下了取消!”);和警报(“测试!”);是占位符。实际上,我不想让其他人做任何事情。

更改行:

$("input[title$='Derived']").click(function() {
    if ($("input[title$='Derived']").is(":checked")) {
         if(confirm("Message here"))
         {
            //do something
         }
    }
}
else {
致:


另外,正如AD.Net指出的,您可能希望用
$(this)

替换第二个
$(“input[title$='Derived']”)来代替
(这)

嵌套ifs没有根本性的错误,这表明代码中还有其他错误。第一个if不应该是:if($(this).is(“:checked”)){….顺便说一句,是的,你可以做到,使用if语句没有什么错。看起来你缺少了外部if语句的结束括号。
} else {