本文實例講述了JS CSS實作模仿瀏覽器網頁字元尋找功能的方法。分享給大家供大家參考。具體實作方法如下: 複製程式碼 程式碼如下: JS+CSS模仿的网页字符查找功能 <br> BODY { <br> FONT-SIZE: 12px; LETTER-SPACING: 1pt; LINE-HEIGHT: 22px; MARGIN-LEFT: 5pt; MARGIN-TOP: 5pt <br> } <br> #scontentmain { <br> HEIGHT: 30px; POSITION: absolute; TOP: 28px; WIDTH: 228px <br> } <br> #scontentbar { <br> BORDER-BOTTOM: black 1px solid; BORDER-LEFT: black 1px solid; BORDER-RIGHT: black 1px solid; BORDER-TOP: black 1px solid; CURSOR: hand; HEIGHT: 15px; PADDING-BOTTOM: 1px; PADDING-LEFT: 1px; PADDING-RIGHT: 1px; PADDING-TOP: 1px; POSITION: absolute; TOP: 5px; WIDTH: 100% <br> } <br> #scontentsub { <br> POSITION: absolute; TOP: 28px; WIDTH: 100% <br> } <br> A.a1:hover { <br> BORDER-BOTTOM: #4a8ff2 1px solid; BORDER-LEFT: #4a8ff2 1px solid; BORDER-RIGHT: #4a8ff2 1px solid; BORDER-TOP: #4a8ff2 1px solid; LINE-HEIGHT: 13pt; WIDTH: 83px; 12px;: 1869FE; align: center <br> } <br> A.a1:link { <br> COLOR: #ffffff; TEXT-DECORATION: none; 12px;align: center <br> } <br> TD { <br> FONT-SIZE: 12px <br> } <br> .pos { <br> POSITION: relative <br> } <br> 中国晋州百战疲劳壮士哀洛黄损江淮宝马夸张美国AjaxASPJAVAJQUERY <br> var dragapproved=false <br> var zcor,xcor,ycor <br> function drag_onclick() { <br> if (search1.drag.checked == true ) dragapproved=false <br> else dragapproved=true <br> } <br> function movescontentmain(){ <br> if (event.button==1&&dragapproved&&search1.drag.checked == true){ <br> zcor.style.pixelLeft=tempvar1+event.clientX-xcor <br> zcor.style.pixelTop=tempvar2+event.clientY-ycor<br> leftpos=document.all.scontentmain.style.pixelLeft-document.body.scrollLeft <br> toppos=document.all.scontentmain.style.pixelTop-document.body.scrollTop <br> return false <br> } <br> } <br> function dragscontentmain(){ <br> if (!document.all) <br> return <br> if (event.srcElement.id=="scontentbar"){ <br> dragapproved=true <br> zcor=scontentmain <br> tempvar1=zcor.style.pixelLeft <br> tempvar2=zcor.style.pixelTop <br> xcor=event.clientX <br> ycor=event.clientY <br> document.onmousemove=movescontentmain <br> } <br> } <br> document.onmousedown=dragscontentmain <br> document.onmouseup=new Function("dragapproved=false") <br> function aa(e) <br> { <br> if (e==0) alert("\n- = 页面搜索引擎 1.0 = \n\n\n- 重写了部分代码 - 修正鼠标拖动跳跃的bug, - 保留选择可否拖动……"); <br> return; <br> } <br> function cose() <br> { <br> if(confirm("即将关闭此窗口,如确认请按确定!\n\n如要重开此窗口请刷新页面。")) <br> scontentmain.style.display='none' <br> else <br> scontentmain.style.display='' <br> } <br> document.write('<div id="scontentmain"><form name="search1" onSubmit="return findInPage(this.Word.value);"><div id="scontentbar">点击下面复选框,按住此处拖动</div><div id="scontentsub"" style="visibility: show"><table width="228" border="1" cellpadding="2" cellspacing="0" bordercolorlight="#000000" bordercolordark="#FFFFFF" bgcolor="#0099CC" class=font1><tr bgcolor="#2D96FF"><td height="2" colspan="2" align="center"><input type="text" name="Word" size="30" onChange="n = 0;" onFocus=window.document.search1.Word.value="" style="background-image: url()" ></td></tr><tr bgcolor="#CCCCCC"><td width="222"> <input type="checkbox" name="drag" value="搜索" LANGUAGE=javascript onclick="return drag_onclick()">可用鼠标拖动窗口 <a href="#top"></a></td><td width="61" align="center"><input type="submit" name="Submit" value="搜索"></td></tr></form></table></div></DIV>'); <br> var w=document.body.clientWidth-450 <br> var h=190 <br> w =document.body.scrollLeft <br> h =document.body.scrollTop <br> var leftpos=w <br> var toppos=h <br> scontentmain.style.left=w <br> scontentmain.style.top=h <br> 函數 ondisplay(){ <br> if (scontentsub.style.display=='') <br> scontentsub.style.display='無'<br> 否則<br> scontentsub.style.display=='' <br> } <br> 函數offdisplay(){ <br> if (scontentsub.style.display=='none') <br> scontentsub.style.display='' <br> 否則<br> scontentsub.style.display=='無'<br> } <br> 函數靜態化(){ <br> w2=document.body.scrollLeft leftpos <br> h2=document.body.scrollTop toppos <br> scontentmain.style.left=w2 <br> scontentmain.style.top=h2 <br> } <br> window.onscroll=靜態化 <br> 函數 GetWord() <br> { <br> var tr <br> } <br> 函數 FindWord(w) <br> { <br> for (var i=0;i<wordlist.options.length></wordlist.options.length> if (WordList.options[i].text==w) <br> { <br> WordList.options[i].selected=true <br> Output.value=WordExpln[i] <br> RESULT.style.visibility="可見" <br> 回傳 true <br> } <br> 回傳錯誤<br> } <br> var canDrag=0,canGetWord=0 <br> var oldtop=0,oldscrolltop=0 <br> var WordExpln=new Array() <br> var G_xmlHTTP <br> document.onmousemove = GetWord <br> var NS4 = (文檔.層); <br> var IE4 = (文檔.all); <br> var 贏=這個; <br> var n = 0; <br> 函數 findInPage(str) <br> { <br> var txt,i,找到;<br> if (str == "") <br> 返回假;<br> 如果 (NS4) <br> { <br> if (!win.find(str)) <br> while(win.find(str, false, true)) <br> ; <br> 否則<br> ; <br> if (n == 0)alert(str " ...您要尋找的文字不存在。 n請再試一次輸入頁面中關鍵字的查找! } <br> 如果(IE4)<br> { <br> txt = win.document.body.createTextRange(); <br> for (i = 0; i { <br> txt.moveStart("字元", 1); <br> txt.moveEnd("文字編輯"); <br> } <br> 如果(找到)<br> { <br> txt.moveStart("字元", -1); <br> txt.findText(str); <br> txt.select(); <br> txt.scrollIntoView(); <br> ; } <br> 否則<br> { <br> 如果 (n > 0) <br> { <br> n = 0; <br> findInPage(str); <br> } <br> 否則<br> alert(str "...您要尋找的文字不存在。 n請再試一次輸入頁面中關鍵字的查找! } <br> } <br> 返回假;<br> } <br> self.onError=null; <br> 當前X = 當前Y = 0; <br> 它=空; <br> 最後捲動X = 0;最後捲動Y = 0; <br> NS = (文件.層) ? 1:0; <br> IE = (文檔.全部) ? 1:0; <br> > 腳本 <br> 身體><br> </div>