jQuery autocomplete in background of input text box

前端 未结 2 1522
攒了一身酷
攒了一身酷 2021-02-14 15:15

I have a jQuery text box autocomplete script which uses a PHP script to query a MySQL database. Currently, a result is displayed under the text box however I want it to appear a

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-14 16:03

    It looks like Google uses 2 inputs, one with grey text, and another with black text. Then they are overlayed so that the grey text input is on the bottom and the black text input is on top (greater z-index it looks like).

    They grey input contains the full text plus the suggestion and the black input only displays what you typed. Hopefully this can help you figure out the code. Here's Google's html:

    EDIT: Here's a very simplified version of some html and css you could potentially use http://jsfiddle.net/JRxnR/

    #grey
    {
        color: #CCC;
        background-color: transparent;
        top: 0px;
        left: 0px;
        position:absolute;
    }
    #black
    {
        color: #000;
        background-color: transparent;
        z-index: 999;
        top: 0px;
        left: 0px;
        position:absolute;
    }
    
    
    
    

提交回复
热议问题