<script type= "text/web Effects" src= "Web Effects/jquery/jquery.autocomplete.js" ></script>
<link rel= "stylesheet" type= "text/css Course" href= "Js/jquery/jquery.autocomplete.css"/>
<script type= "Text/javascript" >
$ (). Ready (function () {
$ ("#level1name"). AutoComplete ("Levelautocompleteajaxaction.do");
$ ("#level2name"). AutoComplete ("Levelautocompleteajaxaction.do");
$ ("#level3name"). AutoComplete ("Levelautocompleteajaxaction.do");
});
</script>
<input type= "text" id= "Level1name"/>
<input type= "text" id= "Level2name"/>
<input type= "text" id= "Level3name"/>
When used $ ("#level1name") is the ID in the <input type= "text" id= "Level1name"/>,
AutoComplete ("Levelautocompleteajaxaction.do") requests an address for a sent Url,ajax
A few lines of code, so simple!
To support Chinese input, you need to modify the Jquery.autocomplete.js file in several places, in the file of more than 190 lines, plus the following code:
. Bind ("Input", function () {
@hack by Liqt:support to inputing Chinese characters in Firefox
onchange (0, true);
})
Method two automatic pop-up layer
Show ListBox
function Showlstbox ()
{
var txtbox = Window.document.getelementbyid ("textbox1");
var lstbox = Window.document.getelementbyid ("ListBox1");
var strinput = Txtbox.value;
var arrmatch = new Array ();//array of strings to match
var Strmatch; Match a successful string
Arrmatch = ["1111", "AAA", "Klkk1", "Akl1", "2222a", "CCC", "Nanchang", "Nanchang high-tech zone"];
RemoveAll ("ListBox1")
for (var i = 0; i < arrmatch.length; i++)
{
Strmatch = Arrmatch[i];
if (Strmatch.indexof (strinput) >= 0)
{
var opt = document.createelement ("option");
Opt.text = Arrmatch[i].tostring ();
Opt.value = Arrmatch[i];
Lstbox.add (opt);
}
}
if (Lstbox.haschildnodes ())
{
Lstbox.style.display = "block"; Show
}
Else
{
Lstbox.style.display = "none";//Hide
}
}
Remove the contents of the list with ID Listid
function RemoveAll (Listid)
{
var lst = Window.document.getelementbyid (Listid);
var length = Lst.options.length;
for (var i = length; i > 0; i--)
{
Lst.options[i-1].parentnode.removechild (Lst.options[i-1]);
}
}
Copy the contents of the selected item in the ListBox to the text box
function Moveselect () {
var txtbox = Window.document.getelementbyid ("textbox1");
var lstbox = Window.document.getelementbyid ("ListBox1");
var length = Lstbox.options.length;
for (var i = 0; i < length; i++)
{
var lstindex = Lstbox.selectedindex;
if (Lstindex < 0)
Return
Txtbox.value = Lstbox.options[lstindex].text;
}
Hide ListBox after replication completes
Lstbox.style.display = "None";
}