开发者

Replace all text with javascript

I've a php code, it prints some text. But I need to replace "n" character with "N" by JavaScript (without editing php code). In everywhere (All texts). How can I do it? Thanks ...

PS: I was cre开发者_JAVA百科ating another topic (#4459901), but this topic is different!


Before I write this: I don't recommend it. Doing this before outputting to the browser would be your best bit. It's also not great for single characters because it will replace all instances of n with N (i.e. <span> will become <spaN>.

document.body.innerHTML= document.body.innerHTML.replace(/n/g, "N");

Example: http://jsfiddle.net/jonathon/x4akZ/


Use:

replaced = str.replace(/n/g, "N");


You have just to use the replace function, and after your regex, ou must uso /g which means that you want to replace all chars.

"non".replace(/n/g, 'N')
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜