关闭括号和括号

时间:2014-03-11 23:09:58

标签: javascript

问题

我已将三个独立的代码组合在一起,并且无法关闭大括号和括号。看看代码,我怀疑它可能也不正确,虽然我还不完全确定仍在学习JavaScript的过程中。

 $('#form1').submit(function(e) {
        var currentForm = this;
        e.preventDefault();
        bootbox.confirm("Are you sure?", function(result) {

            if (result) {

                console.log('Form Submitted'); //Debug line
        $.ajax({
            type: 'POST',
            url: 'indextest4.php',
            data: $("#form1").serialize(),
            error: function () {
                console.log('Ajax Error');}, //Debug Line

            success: function (response) {

                console.log('Ajax Success'); //Debug Line

                $('.fConfirm').css({
                display:"inline", 
                height: 680, 
                width: 940
                });

                console.log("After CSS change");

            }
        });

    });

另外,如果某种善良的灵魂或许可以告诉我一个经验法则,当你结束使用时我怎么能解决?

  

}

     

})

     

});

5 个答案:

答案 0 :(得分:2)

正确的缩进在这里有很多帮助,因为一切都会顺利排列。以下是我认为您正在寻找的内容:

$('#form1').submit(function(e) {
    var currentForm = this;
    e.preventDefault();
    bootbox.confirm("Are you sure?", function(result) {
        if (result) {
            console.log('Form Submitted'); //Debug line
            $.ajax({
                type: 'POST',
                url: 'indextest4.php',
                data: $("#form1").serialize(),
                error: function () {
                    console.log('Ajax Error');
                }, //Debug Line

                success: function (response) {

                    console.log('Ajax Success'); //Debug Line

                    $('.fConfirm').css({
                        display:"inline", 
                        height: 680, 
                        width: 940
                    });

                    console.log("After CSS change");

                } // success: ...
            }); // $.ajax ...
        } // if (result) ...
    }); // bootbox.confirm ...
}); // $('#form1').submit ...

我在最后添加了所有结束括号的注释,以显示它们对应的内容。

答案 1 :(得分:2)

正如其他人所指出的,这里的关键是缩进您的代码,并使用一个好的编辑器

enter image description here

不是经验法则,但一个提示是在嵌套代码块时添加制表符空间。

大多数编辑器会通过选择它并使用键盘快捷键来识别代码:

在左边:

Shift + 标签

在右边:

标签

答案 2 :(得分:1)

你的最后一行应该是两个花括号。和评论一样,得到一个像Notepad ++这样的好编辑器,他们会向你显示开放和关闭的大括号,标签等

答案 3 :(得分:1)

这应该是正确的:

$('#form1').submit(function(e) {
    var currentForm = this;
    e.preventDefault();
    bootbox.confirm("Are you sure?", function(result) {

        if (result) {

            console.log('Form Submitted'); //Debug line
            $.ajax({
                type: 'POST',
                url: 'indextest4.php',
                data: $("#form1").serialize(),
                error: function () {
                    console.log('Ajax Error');}, //Debug Line

                success: function (response) {

                    console.log('Ajax Success'); //Debug Line

                    $('.fConfirm').css({
                        display:"inline", 
                        height: 680, 
                        width: 940
                    });

                    console.log("After CSS change");

                }
            });
        }
    });
});

答案 4 :(得分:1)

这可能无法解决您的所有问题,但确实可以解决开启和关闭问题。

    $('#form1').submit(function(e) {  //start form submit handler
        var currentForm = this;
        e.preventDefault();
        bootbox.confirm("Are you sure?", function(result) {  //start bootbox.confirm callback
            if (result) {                      //start if block
                console.log('Form Submitted');
                $.ajax({                        //start ajax call
                    type: 'POST',
                    url: 'indextest4.php',
                    data: $("#form1").serialize(),
                    error: function () {            //start ajax error callback
                        console.log('Ajax Error');
                    },                              //end ajax error callback

                    success: function (response) {  //start ajax success callback
                        console.log('Ajax Success'); 
                        $('.fConfirm').css({         //start css change
                            display:"inline", 
                            height: 680, 
                            width: 940
                        });                          // end css change
                        console.log("After CSS change");
                    }                                //end ajax success callback
               });   //end ajax call
           }    //end if block
       });  //end bootbox.confirm
   }); //end form submit handler

这需要一点点练习,但基本的经验法则是关闭你打开的所有内容。是否是'('或' {'。

相关问题