使用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/