Javascript用$替换问题 [英] Javascript replace issue with $
本文介绍了Javascript用$替换问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将以下示例中的this替换为$$ Ashok。我没有得到预期的输出。
I am trying to replace "this" in the below example with "$$Ashok".I am not getting expected output.
var adHtmltext ="this is ashok"
adHtmltext = adHtmltext.replace("this", "$$Ashok");
alert(adHtmltext );
为什么它在输出中显示一个$?如何解决这个问题?
why it is showing one $ in output? how to fix this?
这是jsfiddle http:// jsfiddle.net/RxDa5/
Here is the jsfiddle http://jsfiddle.net/RxDa5/
请帮忙。
推荐答案
查看 MDN文档 :
替换字符串可以包含以下特殊替换模式:
The replacement string can include the following special replacement patterns:
$$
插入$。
所以你必须这样做:
adHtmltext.replace("this", "$$$$Ashok");
参见 Javascript字符串取代怪异 - $$$$折叠为$$ - 这个结果背后的原因是什么?。
这篇关于Javascript用$替换问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文