如何修复jQuery 1.8“语法错误,无法识别的表达式”错误?

时间:2012-08-10 17:16:25

标签: javascript jquery dependencies

<script type="text/javascript">
$(function(){
    $(".user_ava").click(function() {
        $("div:.userMenu",this ).animate({
            height: ["toggle", "swing"],
            opacity: "toggle"
        }, 200, "linear");
    });
});
</script>

错误:消息(未捕获错误:语法错误,无法识别的表达式::。userMenu)

3 个答案:

答案 0 :(得分:4)

"div:.userMenu"中的冒号不正确,jquery无法识别它。 如果要选择<div>userMenu,则语法为

$("div.userMenu",this );

完整脚本:

<script type="text/javascript">
$(function(){
    $(".user_ava").click(function() {
        $("div.userMenu",this ).animate({ // you had a colon here for some reason
            height: ["toggle", "swing"],
            opacity: "toggle"
        }, 200, "linear");
    });
});
</script>

答案 1 :(得分:2)

删除“div:.userMenu”中的“:”

<script type="text/javascript">
$(function(){
    $(".user_ava").click(function() {
        $("div.userMenu",this ).animate({
            height: ["toggle", "swing"],
            opacity: "toggle"
        }, 200, "linear");
    });
});
</script>

答案 2 :(得分:2)

div:.userMenu更改为div.userMenu