javascript實(shí)現(xiàn)劃詞標(biāo)記+劃詞搜索功能
更新時(shí)間:2007年03月06日 00:00:00 作者:
復(fù)制代碼 代碼如下:
<!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('is closed');
}
else{
allow=true;
alert('is opend');
}
}
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='FONT-WEIGHT: bold;COLOR: #ff3366'>").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='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!</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="關(guān)閉/打開(kāi)劃詞功能">
<p>qrasfdasfasfdasfsafasdfsafsafasdfasdfasd</p>
</body>
</html>
在頁(yè)面中加上這串代碼就行了,同時(shí)還有搜索功能。演示效果就請(qǐng)看本BLOG頁(yè)面上用鼠標(biāo)劃選文字的效果
沒(méi)來(lái)得及整理代碼,看上去有點(diǎn)亂。
您可能感興趣的文章:
- javascript實(shí)現(xiàn)網(wǎng)頁(yè)屏蔽Backspace事件,輸入框不屏蔽
- JavaScript實(shí)現(xiàn)檢查頁(yè)面上的廣告是否被AdBlock屏蔽了的方法
- javascript屏蔽右鍵代碼
- JavaScript屏蔽指定區(qū)域內(nèi)右鍵菜單
- JavaScript 關(guān)鍵字屏蔽實(shí)現(xiàn)函數(shù)
- javascript 屏蔽鼠標(biāo)鍵盤(pán)的幾段代碼
- 在textarea中屏蔽js的某個(gè)function的javascript代碼
- 屏蔽鼠標(biāo)右鍵、Ctrl+n、shift+F10、F5刷新、退格鍵 的javascript代碼
- 實(shí)用javaScript技術(shù)-屏蔽類
- javascript過(guò)濾危險(xiǎn)腳本方法
- JavaScript實(shí)現(xiàn)自動(dòng)對(duì)頁(yè)面上敏感詞進(jìn)行屏蔽的方法
相關(guān)文章
如何在JavaScript中實(shí)現(xiàn)私有屬性的寫(xiě)類方式(一)
這篇文章主要介紹了如何在JavaScript中實(shí)現(xiàn)私有屬性的寫(xiě)類方式。需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助2013-12-12在IE下獲取object(ActiveX)的Param的代碼
在IE下,獲取Param的時(shí)候有個(gè)詭異現(xiàn)象(不知道算不算bug)。2009-09-09簡(jiǎn)單實(shí)現(xiàn)節(jié)流函數(shù)和防抖函數(shù)過(guò)程解析
這篇文章主要介紹了簡(jiǎn)單實(shí)現(xiàn)節(jié)流函數(shù)和防抖函數(shù)過(guò)程解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-10-10JS使用ajax方法獲取指定url的head信息中指定字段值的方法
這篇文章主要介紹了JS使用ajax方法獲取指定url的head信息中指定字段值的方法,實(shí)例分析了Ajax操作URL中head信息的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-03-03