我需要删除嵌套的 <b></b>
标签。查看生成的 css,您就会明白问题所在:
<div class="highlight" contenteditable="true">
ahuasdhuasdhuasdhu
<b>
<b>#</b>
huadshuashud
</b>
</div>
我想删除里面有“#”的标签,但我不想删除“#”。 (注意主题标签可以是任何其他值)。为此,我编写了以下代码:
// Highlight already been declared and just is a simple $('.highlight').
highlight.children('b').children('b').contents().unwrap();
现在我有以下代码:
<div class="highlight" contenteditable="true">
ahuasdhuasdhuasdhu
<b>
"#"
"huadshuashud"
</b>
</div>
我想加入这两个字符串,因为当我双击它时,它只是选择“#”或“huadshuashud”,但我希望标签内的所有内容都被选中。
有什么方法可以改进我的方法或连接这两个字符串吗?
最佳答案
尝试:
$('.highlight > b').html(function(){
return $(this).text();
});
这会给你这个:
<b>
#
huadshuashud
</b>
关于javascript - 在 JavaScript/jQuery 中连接字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19261932/