当前位置:
代码迷
>>
综合
>> 可以虚拟定位的
详细解决方案
可以虚拟定位的
热度:
63
发布时间:
2023-09-10 08:09:45.0
可以虚拟定位的
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>javascript实现划词标记划词搜索功能 </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="搜索相关"; } 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>dt猫是一个专业的收集各类脚本学习资料的网站,尽量修正错误打造精品脚本类学习网站,我们为大家游戏脚本资源,源码,软件,asp,php,javascript等编程资料,是网页制作,网络编程,网站建设人士的聚集场所。</p> </body> </html>
[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]
在页面中加上这串代码就行了,同时还有搜索功能。 可以虚拟定位的
查看全文
相关解决方案