jQuery.html出了点问题

jQuery .html something wrong

本文关键字:问题 html jQuery      更新时间:2023-09-26

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

所以,在我的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>

现在这是我在 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");

好的,现在当 r.cast 有一个值时,它可以正常工作并发出警报:"b"和"c"但是当 r.cast 未定义时,什么都不会打印,我收到"a"警报,但没有别的!

这是怎么回事?

("#casting_price") 之前缺少美元符号。

如果您查看控制台,您可能会看到类似于以下内容的消息:

类型错误:"#casting_price".html 不是函数

试试

                $("#casting_price").html("<div class='alert'>Not available for this language and accent</div>");