实现textarea内字符串选择查询替换功能

2016-01-29 11:35 147 1 收藏

实现textarea内字符串选择查询替换功能,实现textarea内字符串选择查询替换功能

【 tulaoshi.com - Javascript 】

 

----------自动替换版----------


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
<HTML
<HEAD
<TITLE New Document </TITLE
<SCRIPT LANGUAGE="JavaScript"
var staus ;
var oRange;
var objTimer;
var objTimer1;
var objTimer2;
var sBookMark;
<!--
function selectall(objAll,OBJSingle){
alert(objAll.checked);
for (var i=0;i<OBJSingle.length;i++){
if (objAll.checked){
for( objs in OBJSingle){
alert(objs.value);
objs.checked=true;
}
}
else{
OBJSingle.checked=false;
}
}
}

function fnSearch() {
fm1.txtarea1.focus();
oRange = fm1.txtarea1.createTextRange();
searchtxt(1);
}

function searchtxt(n){
var v1;
var v2;
var txtr;
var blnS;

window.clearInterval(objTimer1);
window.clearInterval(objTimer2);

v1 = fm1.txtarea1.value;
v2 = fm1.txtarea2.value;
v3 = fm1.txtarea3.value;

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/javascript/)

if( n == 1) {
if (oRange != null) {
oRange.findText(v2);
if  (oRange.findText(v2) == true){
//sBookMark = oRange.getBookmark();
oRange.select();
oRange.scrollIntoView();
objTimer2 = window.setInterval("searchtxt(2)",1000);
}
else{
objTimer = window.setInterval("searchtxt(3)",1000);
}
}
staus = 2 ;
}
else if(n==2)  {
oRange.text = v3;
staus = 1;
objTimer1 = window.setInterval("searchtxt(1)",1000);
}
else if(n==3) {
staus = 3 ;
window.clearInterval(objTimer);
window.clearInterval(objTimer1);
window.clearInterval(objTimer2);
}
}
//--
</SCRIPT
</HEAD
<BODY
<FORM METHOD=POST name="fm1"
<TEXTAREA NAME="txtarea1" ROWS="20" COLS="50"
this is the original text, and this is the string will be repalced.
this is the original text, and this is the string will be repalced.
this is the original text, and this is the string will be repalced.
this is the original text, and this is the string will be repalced.
this is the original text, and this is the string will be repalced.
this is the original text, and this is the string will be repalced.
</TEXTAREA
<TEXTAREA NAME="txtarea2" ROWS="20" COLS="50" will be </TEXTAREA
<TEXTAREA NAME="txtarea3" ROWS="20" COLS="50" has been </TEXTAREA
<input type="button" value="search" onclick="fnSearch()"
</FORM

</BODY
</HTML

--------------------------------手动改进版----------------------------------------

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
<HTML
<HEAD
<TITLE New Document </TITLE
<SCRIPT LANGUAGE="JavaScript"
var oRange;     // save the current textrange 
var intCount = 0;   // this pos of current textrange in the total count
var intTotalCount = 0;  // total count
<!--
//==============================================
//function : fnSearch()
//comment  : Search the text
//param    : none
//return   : none
//author   : Fantiny
//Date     : 10/21/2005
//==============================================
function fnSearch() {

 var strBeReplaced;
 var strReplace;

 strBeReplaced = fm1.txtarea2.value;
 strReplace = fm1.txtarea3.value;

 fnNext();

 fm1.txtarea1.focus();
 oRange = fm1.txtarea1.createTextRange(); //Create a textRange for the Textarea

 
 // Find the text by findtext method
 for (i=1; oRange.findText(strBeReplaced)!=false; i++) {
  if(i==intCount){  
   oRange.select();   // select the finded text
   oRange.scrollIntoView(); // scroll the page and set the text Into View
   break;
  }
  oRange.collapse(false);   //
 }
}

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/javascript/)

//========================================

来源:https://www.tulaoshi.com/n/20160129/1482728.html

延伸阅读
批量替换的具体语法是: 代码如下: UPDATE 表名 SET 指定字段 = replace(指定字段, '要替换的字符串', '想要的字符串') WHERE 条件; 如果你想把 article 表中 ID 小于5000的记录,content 字段中“解决”替换成“解放”,那么语法就是: 代码如下: UPDATE article SET content = replace(content, '解决', '解放') WHERE ID500...
核心语句: UPDATE `cdb_pms` SET `subject` = REPLACE(`subject`, 'Welcome to', '欢迎光临') mysql替换字段里数据内容部分字符串 mysql替换表的字段里面内容,如例子: mysql select host,user from user  where user='testuser'; +-----------------------+----------+ | host       &nbs...
标签: 电脑入门
字符串格式定义 printf()函数 printf()函数是格式化输出函数, 一般用于向标准输出设备按规定格式输出信息。在编写程序时经常会用到此函数。printf()函数的调用格式为: printf("格式化字符串", 参量表); 其中格式化字符串包括两部分内容: 一部分是正常字符, 这些字符将按原样输出; 另一部分是格式化规定字符, 以"%"开始...
标签: Web开发
JS代码如下。 在调用Ajax返回后。一个奇怪的问题。返回的resultString值是“ok”但是跟字符串"ok"比较确不相等。 Ajax调用out.println()返回的都添加了哪些参数? 放开注释的部分也过滤不掉。 哪位高手遇到过类似的问题。 如何解决的。 请说一下。out.println();返回的到底是个啥。 Js代码 代码如下: // 本地下载 function FTPTest(...
标签: SQLServer
/* author:amjn date:2003-03-28 version:1.0 function:替换text,ntext列中的字符串(不支持中文) */ declare @ptr varbinary(16) declare @amjnId int declare @Position int,@len int set @len=datalength('ILOVEHJL') declare wux_Cursor scroll Cursor for select textptr([Name]),[amjnId] from USA201 for re...

经验教程

895

收藏

42
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部