岁数大了,QQ也不闪了,微信也不响了,电话也不来了,但是图老师依旧坚持为大家推荐最精彩的内容,下面为大家精心准备的javascript实现划词标记+划词搜索功能,希望大家看完后能赶快学习起来。
【 tulaoshi.com - Web开发 】
以下是引用片段:!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN"htmlheadtitleUntitledDocument/titlemetahttp-equiv="Content-Type"content="text/html;charset=gb2312"/headbodySCRIPTlanguage=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.length0){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.length0){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://www.google.com/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);}//--/SCRIPTINPUTtype="button"onclick="isallow()"value="关闭/打开划词功能"pqrasfdasfasfdasfsafasdfsafsafasdfasdfasd/p/body/html
来源:http://www.tulaoshi.com/n/20160219/1615556.html
看过《javascript实现划词标记+划词搜索功能》的人还看了以下文章 更多>>