复制代码 代码如下:
<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN">
<html>
<head>
<title>UntitledDocument</title>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312">
</head>
<body>
<SCRIPTlanguage=javascript>
<!--
document.body.onload=adddiv;
document.onmousedown=recordobj;
document.ondblclick=dbclick;
document.onmouseup=showselect;
varstarobj,isdb=false,allow=true;
functionisallow()
{
if(allow){
allow=false;
alert('isclosed');
}
else{
allow=true;
alert('isopend');
}
}
functiondbclick()
{
isdb=true;
}
functionrecordobj()
{
starobj=event.srcElement;
}
functionshowselect(){
varstr="";
if(event.srcElement.tagName!="A"&&event.srcElement.tagName!="INPUT"&&event.srcElement==starobj&&!isdb&&allow)
{
varoText=document.selection.createRange();
if(oText.text.length>0)
{
str=oText.text;
oText.text="BuB"+oText.text+"EuE";
}
oText.select();
event.srcElement.innerHTML=event.srcElement.innerHTML.replace("BuB","<ustyle='FONT-WEIGHT:bold;COLOR:#ff3366'>").replace("EuE","</u>");
}
searchgoogle(str)
isdb=false;
}
functionsearchgoogle(str)
{
varobj=document.getElementById("searchgoogle");
if(str.length>0)
{
obj.style.display="block";
obj.style.position="absolute";
obj.style.zindex=999;
obj.style.posTop=document.body.scrollTop+event.y-25;
obj.style.posLeft=document.body.scrollLeft+event.x+5;
obj.style.widht=80;
obj.innerHTML="<atarget=_blankhref=http:///search?ie=UTF-8&oe=UTF-8&q="+str+"style='BORDER-RIGHT:royalbluethinsolid;BORDER-TOP:royalbluethinsolid;FONT-WEIGHT:bold;BORDER-LEFT:royalbluethinsolid;CLIP:rect(autoautoautoauto);COLOR:#ffffff;BORDER-BOTTOM:royalbluethinsolid;BACKGROUND-COLOR:inactivecaption;TEXT-DECORATION:none'>SearchIt!</a>";
}
else
{
obj.style.display="none";
}
}
functionadddiv()
{
varmobj=document.createElement("div");
mobj.id="searchgoogle";
document.body.appendChild(mobj);
}
//-->
</SCRIPT>
<INPUTtype="button"onclick="isallow()"value="关闭/打开划词功能">
<p>qrasfdasfasfdasfsafasdfsafsafasdfasdfasd</p>
</body>
</html>
在页面中加上这串代码就行了,同时还有搜索功能。演示效果就请看本BLOG页面上用鼠标划选文字的效果
没来得及整理代码,看上去有点乱。
