首页 >web前端 >js教程 >javascript实现划词标记+划词搜索功能_javascript技巧

javascript实现划词标记+划词搜索功能_javascript技巧

WBOY
WBOY原创
2016-05-16 19:18:011502浏览
复制代码 代码如下:

nbsp;HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
 
 
Untitled Document 
 
 

 


<script> <BR><!-- <br><br>document.body.onload=adddiv; <BR>document.onmousedown=recordobj; <BR>document.ondblclick=dbclick; <BR>document.onmouseup=showselect; <BR>var starobj,isdb=false,allow=true; <br><br>function isallow() <BR>{ <BR>if(allow){ <BR>allow=false; <BR>alert('is closed'); <BR>} <BR>else{ <BR>allow=true; <BR>alert('is opend'); <BR>} <br><br>} <br><br>function dbclick() <BR>{ <BR>isdb=true; <BR>} <BR>function recordobj() <BR>{ <BR>starobj=event.srcElement; <BR>} <BR>function showselect() { <BR>var str=""; <BR>if(event.srcElement.tagName!="A"&&event.srcElement.tagName!="INPUT"&&event.srcElement==starobj&&!isdb&&allow) <BR>{ <BR>var oText=document.selection.createRange(); <br><br>if(oText.text.length>0) <BR>{ <BR>str=oText.text; <BR>oText.text="BuB"+oText.text+"EuE"; <BR>} <br><br><BR>oText.select(); <BR>event.srcElement.innerHTML=event.srcElement.innerHTML.replace("BuB","<u style='FONT-WEIGHT: bold;COLOR: #ff3366'>").replace("EuE",""); <br><br>} <br><br>searchgoogle(str) <BR>isdb=false; <BR>} <br><br>function searchgoogle(str) <BR>{ <BR>var obj=document.getElementById("searchgoogle"); <BR>if(str.length>0) <BR>{ <BR>obj.style.display="block"; <BR>obj.style.position="absolute"; <BR>obj.style.zindex=999; <BR>obj.style.posTop=document.body.scrollTop+event.y-25; <BR>obj.style.posLeft=document.body.scrollLeft+event.x+5; <BR>obj.style.widht=80; <BR>obj.innerHTML="<a target=_blank href=http://www.google.com/search?ie=UTF-8&oe=UTF-8&q="+str+" style='BORDER-RIGHT: royalblue thin solid; BORDER-TOP: royalblue thin solid; FONT-WEIGHT: bold; BORDER-LEFT: royalblue thin solid; CLIP: rect(auto auto auto auto); COLOR: #ffffff; BORDER-BOTTOM: royalblue thin solid; BACKGROUND-COLOR: inactivecaption; TEXT-DECORATION: none'>Search It!"; <br><br>} <BR>else <BR>{ <BR>obj.style.display="none"; <BR>} <BR>} <br><br>function adddiv() <BR>{ <BR>var mobj = document.createElement("div"); <br><br>mobj.id="searchgoogle"; <br><br>document.body.appendChild(mobj); <BR>} <br><br>//--> <BR></script> 
 

qrasfdasfasfdasfsafasdfsafsafasdfasdfasd

 
 
 


在页面中加上这串代码就行了,同时还有搜索功能。演示效果就请看本BLOG页面上用鼠标划选文字的效果

没来得及整理代码,看上去有点乱。
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn