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

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

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

【 tulaoshi.com - Javascript 】

 

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

(本文来源于图老师网站,更多请访问http://www.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;

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() {

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

 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);   //
 }
}

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

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

延伸阅读
批量替换的具体语法是: 代码如下: UPDATE 表名 SET 指定字段 = replace(指定字段, '要替换的字符串', '想要的字符串') WHERE 条件; 如果你想把 article 表中 ID 小于5000的记录,content 字段中“解决”替换成“解放”,那么语法就是: 代码如下: UPDATE article SET content = replace(content, '解决', '解放') WHERE ID500...
标签: 电脑入门
字符串格式定义 printf()函数 printf()函数是格式化输出函数, 一般用于向标准输出设备按规定格式输出信息。在编写程序时经常会用到此函数。printf()函数的调用格式为: printf("格式化字符串", 参量表); 其中格式化字符串包括两部分内容: 一部分是正常字符, 这些字符将按原样输出; 另一部分是格式化规定字符, 以"%"开始...
create or replace procedure ModifyLadingItemPack (   ASoditemguid varchar2,                  --合同电子仓单明细GUID   ALadingitemGUID varchar2,             &nb...
标签: 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...
基本要求:需安装WORD FunctionWordReplace(FileNameAsString,SearchStringAsString,ReplaceStringAsString,OptionalSaveFileAsString="",OptionalMatchCaseAsBoolean=False)AsInteger OnErrorGoToErrorMsg'函数运行时发生遇外或错误,转向错误提示信息 DimwordAppAsNewWord.Application DimwordDocAsNewWord.Docu...

经验教程

548

收藏

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