在 textarea 中查找并替换所有匹配的字符串 [英] Find and replace all matching strings within textarea
本文介绍了在 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"));
这篇关于在 textarea 中查找并替换所有匹配的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文