textarea里面向上查找咋弄的折腾了半天都不行

yaoBoss 2010-02-05 07:38:00
早到了向下查找的方法
<script>
$=function(id){
return document.getElementById(id);
}
var rng = "";
var initArea = "";
function findText(oTextArea, oInput) {
if (initArea != oTextArea) {
rng = oTextArea.createTextRange();
initArea = oTextArea;
}
if (oInput.value == "") return; //定义一个变量,作为moveStart()函数的偏移量,即开始点跳过选择文本
var num = 0;
if (document.selection)  num = document.selection.createRange().text.length; //每次调用函数,结束点都为末尾,而开始点是跳过选择文本后的新开始点
rng.moveStart("character", num);
rng.moveEnd("character", oTextArea.value.length);
find = rng.findText(oInput.value); //搜索到后选择文本  
if (find) rng.select();   
if (rng.text != oInput.value) {  
alert("搜索完毕");
}
}
</script>
<input type="text" id="html_search" />
<input type="button" value="查找" onclick="findText($('htmlcode'),$('html_search'),-1)" /><br />
<textarea id="htmlcode" rows="20" cols="100">
</textarea>
折腾半天还是只会向下 向上的咋弄啊
...全文
95 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
yaoBoss 2010-02-05
  • 打赏
  • 举报
回复
折腾过了 不行 啊 谁能搞定啊 能往上查就方便了
xmliy 2010-02-05
  • 打赏
  • 举报
回复
第二个参数设为负值试试
yaoBoss 2010-02-05
  • 打赏
  • 举报
回复
我看过了 向上到底咋弄啊 谁给写两句关键的 啊

iSearchScope

Match backwards.

这两个参数真不明白
xmliy 2010-02-05
  • 打赏
  • 举报
回复
bFound = TextRange.findText(sText [, iSearchScope] [, iFlags])

sText Required. String that specifies the text to find.
iSearchScope Optional. Integer that specifies the number of characters to search from the starting point of the range. A positive integer indicates a forward search; a negative integer indicates a backward search.
iFlags Optional. Integer that specifies one or more of the following flags to indicate the type of search: 0 Default. Match partial words.
1 Match backwards.
2 Match whole words only.
4 Match case.
131072 Match bytes.
536870912 Match diacritical marks.
1073741824 Match Kashida character.
2147483648 Match AlefHamza character.

87,919

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧