Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么这个javascript不能用“替换”替换文本;“心”;象征? (函数($){ $.fn.htmlCodes=函数(){ var$this=这个; var body=this.html(); body=body.replace(“:)”、“☺;”).replace(“_Javascript_Jquery_Html_String - Fatal编程技术网

为什么这个javascript不能用“替换”替换文本;“心”;象征? (函数($){ $.fn.htmlCodes=函数(){ var$this=这个; var body=this.html(); body=body.replace(“:)”、“☺;”).replace(“

为什么这个javascript不能用“替换”替换文本;“心”;象征? (函数($){ $.fn.htmlCodes=函数(){ var$this=这个; var body=this.html(); body=body.replace(“:)”、“☺;”).replace(“,javascript,jquery,html,string,Javascript,Jquery,Html,String,在执行此操作时有效…” (function( $ ) { $.fn.htmlCodes = function(){ var $this = this; var body = this.html(); body = body.replace(':)', '&#9786;').replace('<3', '&#9829;'); this.html(body); }; })( jQuery

在执行此操作时有效…”

(function( $ ) {

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


})( jQuery );
演示:

.html()
将为
A
提供html字符代码
有可能

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

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

})( jQuery );
body = body.replace(':)', '&#9786;').replace('&lt;3', '&#9829;');