<html>
<head>
<script language="javascript">
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;
}
</script>
</head>
<body>
<INPUT id="Text1" type="text" name="Text1">
<INPUT id="Button1" type="button" value="Button" name="Button1" οnclick="findInPage(Text1.value)">
</body>
</html>
转载于:https://www.cnblogs.com/wzhxj/archive/2005/12/24/303733.html