查找并替换textarea中的所有匹配字符串

问题描述:

我有这个

var textarea=$('#content'); 
textarea.html(textarea.html().replace("PID","111111")); 

这部分起作用,但是它只能在文本区域中找到第一个"PID",并将其替换为"1111111".还有大约7个我也需要更改.我需要的是一种找到所有"PID"并将其替换为"111111"的方法.

This works partially, but it only finds the first "PID" within the textarea and replaces it to "1111111". There are about 7 others I need to change as well. What I need is a way to find ALL "PID" and replace it with "111111".

谢谢.

使用正则表达式替换字符串中所有出现的内容.试试这个

Use regex to replace all the occurrences in a string. Try this

textarea.html(textarea.html().replace(/PID/g,"111111"));