文本查找函数

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

你可能感兴趣的:(函数)