jQuery在span中替换html

gri*_*egs 9 jquery

替换<spanjQuery中的内容是否存在问题.

我有这个;

<span class='DimensionList'>
  some html
</span>
Run Code Online (Sandbox Code Playgroud)

$('.DimensionList').html("<b>This is the new html</b>");
Run Code Online (Sandbox Code Playgroud)

我发现在FF中,跨度的内容被添加到.所以新的HTML位于旧的上方.

在IE6中,是的,我必须迎合它,它做的大致相同.

编辑

我编辑了这个问题,以显示替换html中有html

hyb*_*aut 15

由于替换文本中没有标记,请使用text()而不是html():

$('.DimensionList').text("This is the new html");
Run Code Online (Sandbox Code Playgroud)

  • 首先尝试清除范围,然后设置新的html,如$('.DimList').empty().html("<b> hello </ b>"). (3认同)