首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

文本查寻函数

2012-10-07 
文本查找函数function findInPage(str){var txt, i, found,n 0if (str ){return false}txt doc

文本查找函数
function findInPage(str)
{
var txt, i, found,n = 0;
if (str == "")
{
  return false;
}
txt = document.body.createTextRange();
for (i = 0; i <= n && (found = txt.findText(str)) != false; i++)
{
  txt.moveStart("character", 1);
  txt.moveEnd("textedit");
}
if (found)
{
  txt.moveStart("character", -1);
  txt.findText(str);
  txt.select();
  txt.scrollIntoView();
  n++;  
}
else
{
  if (n > 0)
  {
   n = 0;
   findInPage(str);
  }
  else
  {
   alert(str + "...            您要找的文字不存在。\n \n请试着输入页面中的关键字再次查找!");
  }
}
return false;
}

热点排行