gpt4 book ai didi

javascript - 为什么这个 javascript 没有用 "heart"符号替换文本?

转载 作者:太空宇宙 更新时间:2023-11-04 13:36:53 25 4
gpt4 key购买 nike

(function( $ ) {

$.fn.htmlCodes = function(){
var $this = this;
var body = this.html();
body = body.replace(':)', '&#9786;').replace('<3', '&#9829;');
this.html(body);
};


})( jQuery );

我编写了这个 JQuery 插件,以便它将笑脸更改为笑脸实体。 (和心)

可是,心不行啊!出于某种原因,笑脸有效,但心脏无效。

最佳答案

如果你这样做就有效......

.replace('&lt;3', '&#9829;');

演示: http://jsfiddle.net/ZdJh5/

.html()为您提供 < 的 HTML 字符代码符号。

关于javascript - 为什么这个 javascript 没有用 "heart"符号替换文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9371707/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com