开发者

JQuery Nested Conditional

Is it possible to nest conditional statements in JQuery? The code below works if I strip off the outside if but once I add it back it stops working. Can someone tell me if this is even possible? I don't want to go too far checking my syntax for nothing.

$("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?");
          开发者_C百科  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!");
    }
    });

As a side note, the alert("You pressed cancel!"); and alert("Test!"); are placeholders. I actually don't want those elses to do anything.


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


Change the line:

else {

To:

} else {

Also, as AD.Net pointed out, you might want to replace the second $("input[title$='Derived']") with $(this).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜