jQuery .html出错了

Ale*_*dro -2 html javascript jquery

我有一个非常简单的代码,我不明白为什么它不起作用.

所以,我的html中的一些地方我有一张桌子.而这在其中:

<tr>
    <td class="tx-right" colspan="2"><strong>Price</strong></td>
    <td class="td-speedy" id="speedy_price"></td>
    <td class="td-casting" id="casting_price"></td>
    <td class="td-search" id="snb_price"></td>
</tr>
Run Code Online (Sandbox Code Playgroud)

现在这是我在ajax调用中的jQuery代码:

if(typeof r.casting === 'undefined'){
    alert("a");
    ("#casting_price").html("<div class='alert'>Not available for this language and accent</div>");
    alert("d");
}
else
{
    alert("b");
    $("#casting_price").text("$"+ r.casting+" USD");
}
alert("c");
Run Code Online (Sandbox Code Playgroud)

好吧,现在当r.casting有一个值,它工作正常并提醒:"b"和"c"但是当r.casting未定义时,没有打印任何内容,我得到了"a"警报,但没有别的!

这里发生了什么?

Ita*_*tay 7

之前丢失的美元符号("#casting_price").

如果你看一下你的控制台,你可能会看到类似这样的消息:

TypeError:"#casting_price".html不是函数

  • 太晚已经在明天的早间新闻:) (3认同)