本文介绍了告诉我如何替换文本框中的所有单词实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 有人可以告诉我如何最好地这样做吗?..... 我有一个文本框,我想搜索它的内容并更换 某个单词的所有实例,并用某些东西替换该单词 else。出于此目的,它可以替换绿色。与 蓝色。有人可以告诉我如何正确地做到这一点? :) 真诚的问候,Alxasa。 Hi, can someone please show me how to most elegently do this?..... I have a textbox, and I want to search the contents of it and replaceall instances of a certain word, and replace that word with somethingelse. For the purposes of this it could be replacing "green" with"blue". Can someone please show me how to properly do this? :) Sincerest regards, Alxasa. 推荐答案 < SCRIPT> re = / apples / gi; str ="苹果是圆形的苹果很多汁。; newstr = str.replace(re,oranges); document.write(newstr) < / SCRIPT> ---------------------------------- ----------------------------- jn ****** @ yourpantsyahoo.com.au :脱掉裤子回复 -------------- ------------------------------------------------- <SCRIPT>re = /apples/gi;str = "Apples are round, and apples are juicy.";newstr=str.replace(re, "oranges");document.write(newstr)</SCRIPT>--------------------------------------------------------------- jn******@yourpantsyahoo.com.au : Remove your pants to reply--------------------------------------------------------------- < SCRIPT> re = / apples / gi; str ="苹果是圆的苹果很多汁。; newstr = str.replace(re,oranges); document.write(newstr) < / SCRIPT> ---------------------------------- ----------------------------- jn ****** @ yourpantsyahoo.com.au :脱掉裤子回复 -------------- ------------------------------------------------- <SCRIPT>re = /apples/gi;str = "Apples are round, and apples are juicy.";newstr=str.replace(re, "oranges");document.write(newstr)</SCRIPT>--------------------------------------------------------------- jn******@yourpantsyahoo.com.au : Remove your pants to reply--------------------------------------------------------------- :)你能告诉我如何做同样的事情来实现 textarea吗? < ; textarea id = sunny cols = 25>苹果是圆的,苹果是多汁。< / textarea> < SCRIPT> re = / apples / gi; str ="苹果是圆的,苹果很多。; newstr = str.replace( re,oranges); document.write(newstr) < / SCRIPT > :) Could you pls show me how to do that same thing to effect atextarea? <textarea id=sunny cols=25>Apples are round, and apples arejuicy.</textarea> <SCRIPT>re = /apples/gi;str = "Apples are round, and apples are juicy.";newstr=str.replace(re, "oranges");document.write(newstr)</SCRIPT> <!DOCTYPE html PUBLIC" - // W3C // DTD XHTML 1.0 Strict // EN" " http: //www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> < html xmlns =" http://www.w3.org/1999/xhtml" ;> < head> < meta http-equiv =" Content-Type"含量=" text / html的;字符集= UTF-8英寸/> < title> Untitled Document< / title> < script type =" text / javascript"> function ReplaceApples() { // ---设置正则表达式字符串 re = / apples / gi; // ---- get element id = document.getElementById(" sunny"); // ---获取元素中的文字 str = id.value; // ---做正则表达式替换 newstr = str.replace(re," oranges"); // ---将新值保存回元素 id.value = newstr; } < ; / script> < / head> < body> < textarea id =" sunny" cols = 25>苹果是圆的,苹果是多汁。< / textarea> < input name =" btn"类型= QUOT按钮" onclick =" ReplaceApples()" value =" Change" /> < / body> < / html> ------------- -------------------------------------------------- jn******@yourpantsyahoo.com.au :脱掉裤子回复 ------------------------------------------- -------------------- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Untitled Document</title><script type="text/javascript">function ReplaceApples(){//--- setup regex stringre = /apples/gi;//---- get elementid = document.getElementById("sunny");//--- get text within elementstr = id.value;//--- do regex replacenewstr=str.replace(re, "oranges");//--- save new value back to elementid.value = newstr;}</script></head><body><textarea id="sunny" cols=25>Apples are round, and apples arejuicy.</textarea><input name="btn" type="button" onclick="ReplaceApples()"value="Change" /></body></html>--------------------------------------------------------------- jn******@yourpantsyahoo.com.au : Remove your pants to reply--------------------------------------------------------------- 这篇关于告诉我如何替换文本框中的所有单词实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-12 22:22