使用JS查找并替换文档中的特定文本字符 [英] Find and replace specific text characters across a document with JS
本文介绍了使用JS查找并替换文档中的特定文本字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否有一种轻量级的方式我可以使用JavaScript或jQuery来嗅出文档中的特定文本字符;说€并查找此角色的所有实例。 然后!使用 $ 编写替换所有实例的功能。
I'm wondering if there is a lightweight way I could use JavaScript or jQuery to sniff out a specific text character across a document; say € and find all instances of this character. And then! Write an ability to replace all instances of this with say a $.
我找到了这个代码段首发:
I found this snippet for starters:
var str = 'test: '';
str = str.replace(/'/g, "'");
基本上;我想要一个单页文档的解决方案。抓住X的所有实例并使其成为XY。只有文字字符。
Essentially; I am wanting a solution for a one page document. Grab all instances of X and make it XY. Only text characters.
推荐答案
如何用 @
> $ :
How about this, replacing @
with $
:
$("body").children().each(function () {
$(this).html( $(this).html().replace(/@/g,"$") );
});
http://jsfiddle.net/maximua/jp96C/1/
这篇关于使用JS查找并替换文档中的特定文本字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文