我想清除“正常文本”,但没有字形。
\n\n重要的代码部分及其结果:
\n\n$("#btn_test").html()会给我:
"<span class="glyphicon glyphicon-floppy-disk"\naria-hidden="true"></span> Speichern & schlie\xc3\x9fen"
$("#btn_test").text()会给我:
" Speichern & schlie\xc3\x9fen"
我只想删除文本 " " Speichern & schlie\xc3\x9fen",不带.replace(...)-function (因为文本是动态的)。
我尝试过$("#btn_test").text(""),但这也会清除我的跨度元素。
谢谢。
\n\n更新(\'可能重复\'): \n是的,这是与这里相同的问题,但不是克里斯·戴维斯的答案,它解决了我的问题。
\n删除文本节点,例如:
$('#btn_test').contents().filter(function(){
return this.nodeType === 3;
}).remove();
Run Code Online (Sandbox Code Playgroud)
或者更简单,如果它总是最后一个:
$('#btn_test').contents().last().remove();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
420 次 |
| 最近记录: |