</html>
<head>
<title>javascript</title>
<script type="text/javascript">
function fin(i)
{
if(window.find(i,true))
alert(i+"找到了");
else
alert("没有这个词");
}
</script>
</head>
<body>
<p>搜素下面文字</p>
<blockquote>
<hr>
今天天气真好,万里无云
<hr>
</blockquote>
<form>
<input type="text" name="a" value=" ">在这里输入要搜素的词</input>
<input type="button" name="b" value="搜素" onClick="fin(a.value)"></input>
</form>
</body>
</html>
<head>
<title>javascript</title>
<script type="text/javascript">
function fin(i)
{
if(window.find(i,true))
alert(i+"找到了");
else
alert("没有这个词");
}
</script>
</head>
<body>
<p>搜素下面文字</p>
<blockquote>
<hr>
今天天气真好,万里无云
<hr>
</blockquote>
<form>
<input type="text" name="a" value=" ">在这里输入要搜素的词</input>
<input type="button" name="b" value="搜素" onClick="fin(a.value)"></input>
</form>
</body>
</html>
bFound = object.findText(sText [, iSearchScope] [, iFlags])Parameter Description
sText String specifying the text to find.
iSearchScope Optional. An integer indicating the direction 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. A combination of one or more of the following flags indicating the type of search: 2 match whole words only.
4 match case.
Return ValueReturns true if the search text is found, or false otherwise.
function FindText(text)
{
if (window.find) return window.find(text, true);
var range = document.body.createTextRange();
if (range.findText(text, -1))
{
range.scrollIntoView();
range.select();
return true;
}
return false;
}function fin(i)
{
if (FindText(i))
alert(i + "找到了");
else alert("没有这个词");
}
</script>
window.findText()是ff里的,ie中得用TextRange.findText()