JQuery:.hide()不是一个有效的函数。

5

Firebug在抱怨这行代码:

$("#original-description").text(response['course']['original_description']).hide();

我是否有语法错误?在我看来一切正常。

更多上下文:

bindOnSuccess($('#course-search'), function(response) {
    if (!response) {
        $("#system-status").text("Sorry, no course could be found for that search.");
    }
    else {
        $(".dept-code").text(response['course']['dept_code']);
        $(".course-number").text(response['course']['number']);
        $(".course-title").text(response['course']['title']);

        $("#div-original-description").show();
        $("#original-description-teaser").show();

                    // error here
        $("#original-description").text(response['course']['original_description']).hide();

        $("#td-required-for").text(response['analysis']['cRequiredFor']);
    }
});

response 是一个 JSON 对象。这个问题可能是由于无效的下标引起的吗?

Firebug 的错误信息为:

$("#original-description").text(response.course.original_description).hide is not a function

当你看到“x”不是一个函数时,这通常意味着你认为在“x”中的函数对象并不存在。请记住,所有“未知”的属性都会返回undefined--而undefined绝对不是一个函数。 - user166390
1个回答

4
其他回答有误 - .text()返回的是jQuery对象。你可能引用了一个未定义的属性。我可以复现这个问题:
$('<p>').text(undefined).hide()

确保您在JSON中引用了正确的属性。

 TypeError: $("<p>").text(undefined).hide is not a function { message="$("<p>").text(undefined).hide is not a function",  more...}

如果您想实时查询对象,只需在回调函数中执行 window.o = response ,然后在 Firebug 控制台中进行操作即可。

尝试使用 $('<p>').text('' + o.undefinedProp).hide(); - Walf

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接