Javascript 如何在标记中插入文本和html,其中文本显示在第一位,html显示在第二位
我一直在网上寻找,但没有找到正确的解决办法 我在这里用html擦除文本内容,我需要两者 在标记上,我需要如下内容:Javascript 如何在标记中插入文本和html,其中文本显示在第一位,html显示在第二位,javascript,jquery,Javascript,Jquery,我一直在网上寻找,但没有找到正确的解决办法 我在这里用html擦除文本内容,我需要两者 在标记上,我需要如下内容: <h1 class="stock-count">54<span class="stock-count-info">In Stock</span></h1> 但我一直得到一些没有54的东西: <h1 class="stock-count"><span class="stock-count-info">In St
<h1 class="stock-count">54<span class="stock-count-info">In Stock</span></h1>
但我一直得到一些没有54的东西:
<h1 class="stock-count"><span class="stock-count-info">In Stock</span></h1>
这是我尝试过的jQuery代码:
$(".stock-count").text(count);
$(".stock-count").html("<span class='stock-count-info'></span>");
$(".stock-count-info").text("In Stock");
有人有什么建议吗
注:span标记必须位于h1标记内。尝试以下操作:您可以在一次调用中将count和stock count info span直接添加到stock count span的html中
$(".stock-count").html(count+"<span class='stock-count-info'>In Stock</span>");
您可以使用。附加:
使用prepend在前面插入元素
$(".stock-count").html("<span class='stock-count-info'></span>").prepend(count);
只需通过串联将所有功能集于一身即可。
$(".stock-count").html("<span class='stock-count-info'></span>").prepend(count);