Javascript Java脚本快捷方式错误

Javascript Java脚本快捷方式错误,javascript,jquery,Javascript,Jquery,尝试一门关于代码学院的课程。该代码用于在按下O键(111)时触发物品打开。但我听说 “未捕获的语法错误:意外标记}” 这是我的代码,有人能提供一些建议吗 var main = function() { $('article').click(function() { $('article').removeclass('current'); $('description').hide(); $(this).addclass('current')

尝试一门关于代码学院的课程。该代码用于在按下O键(111)时触发物品打开。但我听说

“未捕获的语法错误:意外标记}”

这是我的代码,有人能提供一些建议吗

var main = function() {

$('article').click(function() {

        $('article').removeclass('current');

        $('description').hide();

        $(this).addclass('current');

        $('article').click(function() {

        $(this).children('.description').show(

            });

    $(document).keypress(function(event) {

        if(event.which === 111) {

            $('.current').children('.description').toggle();

        }

    });

    $(document).ready(main);
我还被告知:“看起来o键没有打开描述。请记住在事件处理程序中切换当前文章的描述。请查看代码说明。”谢谢您缺少一个


这些错误令人沮丧,但随着时间的推移,你会变得更好

请注意,您还没有关闭一些括号(即show())

编辑因为上面的用户Trevor在我之前发现了错误,所以我要看看我是否能为我的帖子增加一点价值

由于在.show()方法中缺少paren,解释器在show方法中找到了}作为参数

ie..show(}

由于.show()方法不接受任何参数,因此导致代码中出现错误。希望这有助于你的理解

例如:

 var main = function() {

  $('article').click(function() {

    $('article').removeclass('current');

    $('description').hide();

    $(this).addclass('current');

    $('article').click(function() {

    $(this).children('.description').show(**)**

        });

$(document).keypress(function(event) {

    if(event.which === 111) {

        $('.current').children('.description').toggle();

    }

});

$(document).ready(main);

您的代码有不匹配的括号和括号。考虑使用帮助你发现错误。固定代码。还要考虑正确地缩进代码。它将帮助你更快地发现拼写错误

var main = function() {
    $('article').click(function() {
        $('article').removeclass('current');
        $('description').hide();
        $(this).addclass('current');
        $('article').click(function() {
            $(this).children('.description').show()
        });
        $(document).keypress(function(event) {
            if(event.which === 111) {
                $('.current').children('.description').toggle();
            }
        });
    });
}
$(document).ready(main);

检查所有的结束括号和括号。你有几个输入错误。用于帮助查找错误感谢帮助人员,现在我遇到了一个“输出意外结束”…有什么建议吗?var main=function(){$('article')。单击(function(){$('article')。removeclass('current');$('description')。hide();$(this)。addclass('current');$('article')。单击(function(){$(this)。children('.description')。show();});$(document)。按键(function(event){if(event.which==111){$('.current').children('.description').toggle();}}}});$(document.ready(main);感谢大家的帮助,现在我遇到了一个“输出意外结束”…有什么建议吗?var main=function(){$('article')。单击(function(){$('article')).removeclass('current');$('description').hide();$(this).addclass('current');$('article')。单击(函数(){$(this).children('.description').show();});$(文档).keypress(函数(事件){if(event.which==111){$('.current').childrent('.description').toggle())}});$(文档).ready(主);
var main = function() {
    $('article').click(function() {
        $('article').removeclass('current');
        $('description').hide();
        $(this).addclass('current');
        $('article').click(function() {
            $(this).children('.description').show()
        });
        $(document).keypress(function(event) {
            if(event.which === 111) {
                $('.current').children('.description').toggle();
            }
        });
    });
}
$(document).ready(main);