JavaScript implementation of the phrase search function correction version _javascript skills

Source: Internet
Author: User
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" > <ptml> <pead> <title>untitled Doc ument</title> <meta http-equiv= "Content-type" content= "text/html"; charset=gb2312 "> </pead> <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 >"). 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= "Search it! "; 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= "Turn off/Open stroke function" > <p> cloud-dwelling community &LT;/P&G T </body> </ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

Adding this string of code to the page also has a search function. Demo effect, please see this blog page with the mouse text selection effect.
PS: Due to support in Chinese, and coding problems we give parameter reference
q= "+encodeuri (str) +", you can add escape or encode or add nothing to your needs.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.