繁体   English   中英

jQuery中的分号语法让我感到困惑

[英]Semicolon syntax in jquery has me baffled

在相当简单的代码中:

<script> 
    $(document).ready(function () {
        $('.showprice').click(function () {
            $(this).parent.children.hide();
        }); 
    })
 </script>

Fiddle中的Jshints对第一行大惊小怪,说,失踪了; 并在最后一行大惊小怪,出现无法恢复的错误。

Q1:我在这里想念什么。 我的怀疑是,它像perl,并且在出现完全不同的错误时抱怨分号。

Q2:指针或链接到更好的方法来跟踪语法错误。


根据下面的第一条答复,我提出了建议的更改,将代码修改为:

我将代码编辑为:

1 < script > 
2     $(document).ready(function () {
3     $('.showprice').click(function () {
4         $(this).parent().children().hide();
5     }); 
6    });
7    < /script>

现在我为失踪烦恼; 在第1行上,“在第6行上有预期的赋值或函数调用
和第7行出现不可恢复的错误。

首先,您应该更改:

$(this).parent.children.hide();

至:

$(this).parent().children().hide();

parent()children()是一种方法。 您需要在这里()

您还需要添加; 在结束}) DOM包装器后,最终代码应如下所示:

$(document).ready(function () {
    $('.showprice').click(function () {
        $(this).parent().children().hide();
    }); 
}); // <-- Here

你忘了放; 在代码的最后)

$(document).ready(function () {
    $('.showprice').click(function () {
        $(this).parent.children.hide();
    }); 
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM