为什么这个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(':)', '☺').replace('<3', '♥'); this.html(body); }; })( jQuery
(function( $ ) {
$.fn.htmlCodes = function(){
var $this = this;
var body = this.html();
body = body.replace(':)', '☺').replace('<3', '♥');
this.html(body);
};
})( jQuery );
演示:
.html()
将为A提供html字符代码
有可能
.replace('<3', '♥');
(function( $ ) {
$.fn.htmlCodes = function() {
var $this = this;
var body = this.html();
body = body.replace(/:\)/g, '☺').replace(/<3/g, '♥');
this.html(body);
};
})( jQuery );
body = body.replace(':)', '☺').replace('<3', '♥');