search

Home  >  Q&A  >  body text

javascript - 这是一个js查找功能,我想知道他是如何查找的,针对整个HTML文件吗?如何改成ID或class呢?如何jquery做呢?

<html>
<META HTTP-EQUIV="Content-Type" content="text/html; charset=gb_2312-80">
<TITLE>WinWebMail</TITLE>
<script language="JavaScript">
<!--

var DOM = (document.getElementById) ? 1 : 0;
var NS4 = (document.layers) ? 1 : 0;
var IE4 = 0;
if (document.all)
{

1

2

<code>IE4 = 1; 

DOM = 0;  </code>

}
var win = window;
var n = 0;
function findIt() {

1

2

<code>if (document.getElementById("searchstr").value != ""

    findInPage(document.getElementById("searchstr").value);  </code>

}

function findInPage(str) {
var txt, i, found;
if (str == "")

1

<code>return false; </code>

if (DOM)
{

1

2

<code>win.find(str, false, true); 

return true;  </code>

return true;
}
if (NS4) {

1

2

3

4

5

6

7

<code>if (!win.find(str)) 

    while(win.find(str, false, true)) 

        n++; 

else 

    n++;

if (n == 0) 

    alert("未找到指定内容.");  </code>

}
if (IE4) {

1

2

3

4

5

<code>txt = win.document.body.createTextRange();

for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) { 

    txt.moveStart("character", 1); 

    txt.moveEnd("textedit"); 

} </code>

if (found) {

1

2

3

4

5

<code>txt.moveStart("character", -1); 

txt.findText(str); 

txt.select(); 

txt.scrollIntoView(); 

n++;  </code>

}
else {

1

2

3

4

5

6

7

<code>if (n > 0) { 

    n = 0; 

    findInPage(str); 

else 

    alert("未找到指定内容."); 

}  </code>

}
return false;
}
// -->
</script>
<BODY>

<input type="text" id="searchstr" size="10"> <input type="button" value="页内查找" onClick="javascript:findIt();">
用来在共享计算机上增强安全性的登录选项是为那些从图书馆、学校或网吧登录的用户设计的. 该登录选项在您退出帐户时能够使浏览器高速缓存中的页面过期. 这表明一旦您退出, 您所访问的页将不能被共享计算机的其他用户查看.
注意: 由于页面没有被高速缓存到您的本地磁盘驱动器中, 因此在使用此选项时您会感觉速度变慢了.

</BODY>
</html>

高洛峰高洛峰2908 days ago788

reply all(0)I'll reply

No reply
  • Cancelreply