本文实例讲述了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> } <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> } <br> self.onError=null; <br> 当前X = 当前Y = 0; <br> 它 = null; <br> 最后滚动X = 0;最后滚动Y = 0; <br> NS = (文档.层) ? 1:0; <br> IE = (文档.全部) ? 1:0; <br> </脚本> <br> </身体><br> </html></div> <p>希望本文对大家介绍的javascript程序设计有所帮助。</p>