JavaScript imitation Baidu input box prompts automatic down-pull full _javascript tips

Source: Internet
Author: User

This article illustrates the JavaScript input box automatic pull up full operation, imitation Baidu, Google search box prompts, the specific contents are as follows

Effect Chart:

Specific code:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" > <HTML> <HEAD> <TITLE> New Document ;/title> <meta name= "generator" content= "EditPlus" > <meta name= "Author" content= "" > <meta NAME= "Keyw Ords "Content=" "> <meta name=" Description "content=" "> <script type=" text/javascript "src=" Jquery.js "> </script> <script type= "Text/javascript" >/* Auto Pull up full zhk/var highlightindex=-1;//the currently highlighted node $ (document). R
 Eady (function () {var wordinput=$ ("#word");
 
  var wordinputoffset=wordinput.offset (); $ ("#auto"). Hide (). CSS ("Border", "1px black Solid"). CSS ("position", "absolute"). CSS ("Top", wordinputoffset.top+
 
 Wordinput.height () +5+ "px"). CSS ("left", wordinputoffset.left+ "px"). Width (wordinput.width () +2); Wordinput.keyup (function (event) {var myevent=event| |
  window.event;
  var Keycode=myevent.keycode; if (keycode>=65&&keycode<=90| |
   keycode==8| |keycode==46) {var wordtext=$ ("#word"). Val ();var autonode=$ ("#auto");
    
    if (wordtext!= "") {var wordnodes=$ ("span");
    Autonode.html ("");
     Wordnodes.each (function (i) {var wordnode=$ (this);
      
     var newdivnode=$ ("<div>"). attr ("id", i);
     Newdivnode.html (Wordnode.text ()). Appendto (Autonode); 
        Newdivnode.mouseover (function () {//mouse enters if (highlightindex!=-1) {$ ("#auto"). Children ("div"). EQ (highlightindex)
       . CSS ("Background-color", "white");
       } highlightindex=$ (this). attr ("id");
      $ (this). CSS ("Background-color", "Red");
      
       }) Newdivnode.mouseout (function () {//mouse remove $ (this). CSS ("Background-color", "white");
       }) Newdivnode.click (function () {//click var comtext=$ (this). text ();
     $ ("#auto"). Hide ();
     Highlightindex=-1;
       $ ("#word"). Val (Comtext);
    }) if (wordnodes.length>0) {autonode.show ();
     }else{autonode.hide ();
     Highlightindex=-1;
    }}else{autonode.hide (); HighLightindex=-1; }}else if (keycode==38| |
       KEYCODE==40) {if (keycode==38) {//Up Var autonodes=$ ("#auto"). Children ("div");
         if (highlightindex!=-1) {Autonodes.eq (highlightindex). CSS ("Background-color", "white");
       highlightindex--;
       }else{highlightindex=autonodes.length-1;
       } if (highlightindex==-1) {highlightindex=autonodes.length-1;
     } autonodes.eq (Highlightindex). CSS ("Background-color", "Red");
       } if (keycode==40) {var autonodes=$ ("#auto"). Children ("div");
       if (highlightindex!=-1) {Autonodes.eq (highlightindex). CSS ("Background-color", "white");
       } highlightindex++;
       if (highlightindex==autonodes.length) {highlightindex=0;
     } autonodes.eq (Highlightindex). CSS ("Background-color", "Red"); }else if (keycode==13) {if (highlightindex!=-1) {var comtext=$ ("#auto"). Hide (). Children ("div"). EQ (Highli
     Ghtindex). text (); HigHlightindex=-1;
     $ ("#word"). Val (Comtext);
      }else{alert (in the text box, "+$" ("#word"). Val () + "" submitted ");
       $ ("#auto"). Hide ();
 
  $ ("#word"). Get (0). blur ();//Lost Focus}}});
  $ ("Input [type= ' button ']"). Click (function () {alert (In the text box, +$ (#word). Val () + "" submitted ");
 
 
}); }) </script> </HEAD> <BODY> <input type= "text" id= "word" > <input type= "button" value= "Submit" &
Gt <div id= "Auto" ></div> <p> <span>aaa</span> <span>abc</span> <span> abd</span> <span>bbc</span> <span>beb</span> <span>cer</span> <span
 >erd</span> <span>beg</span> <p> </BODY> </HTML>

The above is the entire content of this article, I hope to learn JavaScript program to help you.

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.