代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
JS
】
实现textarea内字符串选择查询替换功能
作者:
李敬塔
/ 发布于
2012/12/5
/
739
<!-- -- cateDate: 2009-06-13 --author:李敬塔 --> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <!-- saved from url=(0076)http://www.why100000.com/%5Flab/docs/js_code/textarea_search_replace/man.htm --> <HTML><HEAD><TITLE>New Document</TITLE> <META http-equiv=Content-Type content="text/html; charset=gb2312"> <META content="MSHTML 6.00.2900.2180" name=GENERATOR></HEAD> <BODY onload=init()><BR>实现textarea内字符串选择查询替换功能<BR>--------------------------------手动替换---------------------------------------- <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); // } } //============================================== //function : fnSearch() //comment : set the flag to the next textrange //param : none //return : none //author : Fantiny //Date : 10/21/2005 //============================================== function fnNext(){ if (intCount > 0 && intCount < intTotalCount){ intCount = intCount + 1; } else{ intCount = 1 ; } } //============================================== //function : init() //comment : initialize at page onload to get the count //param : none //return : none //author : Fantiny //Date : 10/21/2005 //============================================== function init(){ var oRange ; var strBeRepalced; oRange = fm1.txtarea1.createTextRange(); //Create a textRange for the Textarea strBeReplaced = fm1.txtarea2.value; for (i=0; oRange.findText(strBeReplaced)!=false; i++) { oRange.collapse(false); // Moves the insertion point to the end of the text range. } intTotalCount = i ; } //============================================== //function : fnReplace() //comment : replace the text of the selected textrange //param : none //return : none //author : Fantiny //Date : 10/21/2005 //============================================== function fnReplace(){ var strReplace; strReplace = fm1.txtarea3.value; // if the textrange is exist, replace the text if(oRange!= null && typeof(oRange)=="object" && intTotalCount > 0){ oRange.text = strReplace; intCount = intCount - 1; intTotalCount = intTotalCount - 1; oRange = null; } } //--> </SCRIPT> <FORM name=fm1 method=post><TEXTAREA name=txtarea1 rows=14 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=14 cols=30> will be </TEXTAREA> <TEXTAREA name=txtarea3 rows=14 cols=50> has been </TEXTAREA> <INPUT onclick=fnSearch() type=button value=search> <INPUT onclick=fnReplace() type=button value=Replace> </FORM></BODY></HTML> 上面的的手动替换啦,要不来个自动的? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <!-- saved from url=(0076)http://www.why100000.com/%5Flab/docs/js_code/textarea_search_replace/man.htm --> <HTML><HEAD><TITLE>New Document</TITLE> <META http-equiv=Content-Type content="text/html; charset=gb2312"> <META content="MSHTML 6.00.2900.2180" name=GENERATOR></HEAD> <BODY onload=init()><BR>实现textarea内字符串选择查询替换功能<BR>--------------------------------手动替换---------------------------------------- <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); // } } //============================================== //function : fnSearch() //comment : set the flag to the next textrange //param : none //return : none //author : Fantiny //Date : 10/21/2005 //============================================== function fnNext(){ if (intCount > 0 && intCount < intTotalCount){ intCount = intCount + 1; } else{ intCount = 1 ; } } //============================================== //function : init() //comment : initialize at page onload to get the count //param : none //return : none //author : Fantiny //Date : 10/21/2005 //============================================== function init(){ var oRange ; var strBeRepalced; oRange = fm1.txtarea1.createTextRange(); //Create a textRange for the Textarea strBeReplaced = fm1.txtarea2.value; for (i=0; oRange.findText(strBeReplaced)!=false; i++) { oRange.collapse(false); // Moves the insertion point to the end of the text range. } intTotalCount = i ; } //============================================== //function : fnReplace() //comment : replace the text of the selected textrange //param : none //return : none //author : Fantiny //Date : 10/21/2005 //============================================== function fnReplace(){ var strReplace; strReplace = fm1.txtarea3.value; // if the textrange is exist, replace the text if(oRange!= null && typeof(oRange)=="object" && intTotalCount > 0){ oRange.text = strReplace; intCount = intCount - 1; intTotalCount = intTotalCount - 1; oRange = null; } } //--> </SCRIPT> <FORM name=fm1 method=post><TEXTAREA name=txtarea1 rows=14 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=14 cols=30> will be </TEXTAREA> <TEXTAREA name=txtarea3 rows=14 cols=50> has been </TEXTAREA> <INPUT onclick=fnSearch() type=button value=search> <INPUT onclick=fnReplace() type=button value=Replace> </FORM></BODY></HTML>
试试其它关键字
查询替换
同语言下
.
Jquery搜索框获取回车事件
.
H5页面添加倒计时,然后自动跳转
.
通过user-agent判断h5页面是在哪个手机App(QQ、微信
.
nginx 禁止未绑定的域名访问
.
JavaScript 获取按键,并屏蔽系统 Window 事件
.
H5之只允许微信浏览器打开,禁止从外部浏览器访问
.
微信打开网址添加在浏览器中打开提示的办法
.
实现JS复制、粘贴,Chrome/Firefox下可用
.
video视频播放,play()、pause()、duration时长、onen
.
HTML5实现MP3上传前的预览和播放时长的获取
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
李敬塔
贡献的其它代码
(
13
)
.
PHP模拟登录获取邮箱联系人地址
.
HTML节点交换(兼容FF/IE)
.
js数组分页
.
兼容FF的右键菜单
.
实现textarea内字符串选择查询替换功能
.
SQL的形式操作文件
.
可以传对像的setTimeout函数
.
音频播放器
.
仿 MSN网站首页弹出式欢迎词(兼容Firefox/IE)
.
支持IE、FF纯js 颜色选择器
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3