职业IT人-IT人生活圈

 找回密码
 成为会员
搜索
查看: 2490|回复: 0

javascript实现划词标记+划词搜索功能代码实例

[复制链接]
难道 发表于 2007-8-14 11:31 | 显示全部楼层 |阅读模式
<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\">
</head>
<body>

<SCRIPT language=javascript>
<!--
document.body.onload=adddiv;
document.onmousedown=recordobj;
document.ondblclick=dbclick;
document.onmouseup=showselect;
var starobj,isdb=false,allow=true;
function isallow()
{
if(allow){
allow=false;
alert(&#39;is closed&#39;);
}
else{
allow=true;
alert(&#39;is opend&#39;);
}
}
function dbclick()
{
isdb=true;
}
function recordobj()
{
starobj=event.srcElement;
}
function showselect() {
var str=\"\";
if(event.srcElement.tagName!=\"A\"&&event.srcElement.tagName!=\"INPUT\"&&event.srcElement==starobj&&!isdb&&allow)
{
var oText=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\",\"<u style=&#39;FONT-WEIGHT: bold;COLOR: #ff3366&#39;>\").replace(\"EuE\",\"</u>\");
}
searchgoogle(str)
isdb=false;
}
function searchgoogle(str)
{
var obj=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=\"<a target=_blank href=http://www.google.com/search?ie=UTF-8&oe=UTF-8&q=\"+str+\" style=&#39;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&#39;>Search It!</a>\";
}
else
{
obj.style.display=\"none\";
}
}
function adddiv()
{
var mobj = document.createElement(\"div\");
mobj.id=\"searchgoogle\";
document.body.appendChild(mobj);
}
//-->
</SCRIPT>
<INPUT type=\"button\" onclick=\"isallow()\" value=\"关闭/打开划词功能\">
<p>qrasfdasfasfdasfsafasdfsafsafasdfasdfasd</p>
</body>
</html>
您需要登录后才可以回帖 登录 | 成为会员

本版积分规则

QQ|手机版|小黑屋|网站帮助|职业IT人-IT人生活圈 ( 粤ICP备12053935号-1 )|网站地图
本站文章版权归原发布者及原出处所有。内容为作者个人观点,并不代表本站赞同其观点和对其真实性负责,本站只提供参考并不构成任何投资及应用建议。本站是信息平台,网站上部分文章为转载,并不用于任何商业目的,我们已经尽可能的对作者和来源进行了通告,但是能力有限或疏忽造成漏登,请及时联系我们,我们将根据著作权人的要求立即更正或者删除有关内容。

GMT+8, 2024-5-6 02:20 , Processed in 0.132007 second(s), 20 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表