在不清除其他内容的情况下更改元素的文本
Change the text of an element without wiping out the other contents
我有一个按钮:
<button class="btn btn-primary btn-round like" id="num-likes-entity-{{ key['post'].id }}" >
<i class="far fa-heart"></i>{{ key['totalLikes'] }}
</button>
当有人点击这个点赞按钮时,我想增加点赞的次数 ({{ key['totalLikes'] }}) 而不会删除 <i>
标签。
使用 .text()
清除 <i>
标签。如何在不删除 <i>
标签的情况下替换文本?
正如 Dylan Steele 在上述评论中所说,"wrap the text in a span tag and add an id so you interact with it easier"。
我有一个按钮:
<button class="btn btn-primary btn-round like" id="num-likes-entity-{{ key['post'].id }}" >
<i class="far fa-heart"></i>{{ key['totalLikes'] }}
</button>
当有人点击这个点赞按钮时,我想增加点赞的次数 ({{ key['totalLikes'] }}) 而不会删除 <i>
标签。
使用 .text()
清除 <i>
标签。如何在不删除 <i>
标签的情况下替换文本?
正如 Dylan Steele 在上述评论中所说,"wrap the text in a span tag and add an id so you interact with it easier"。