jquery implementation Select drop-down box can input + Lenovo associated option

Source: Internet
Author: User
Tags lenovo java se

The following code is excerpted from http://www.oschina.net/question/96791_12832

<script language= "javascript" src= "Jquery-1.4.1.js" ></script>
<script>


$ (document). Ready (function () {
var cus = 0;
var classname = "";
var arry = new Array ();
var $autocomplete = $ ("<ul class= ' AutoComplete ' ></ul>"). Hide (). InsertAfter ("#box4");
$ ("#hoho"). Find ("option"). each (function (i, n) {
Arry[i] = $ (this). Text ()
});

$ ("#box4"). focus (function () {if ($ ("#box4"). val () = = = = = = = = = = = = = = = = = = = = = = = ("#box4"). Val ("");
$ ("#box4"). blur (function () {if ($ ("#box4"). val () = = "") {$ ("#box4"). val ("= = = = = = = = = = =");});
$ ("#box4"). KeyUp (function (event) {
if (event.keycode! =) && (event.keycode! =) && (event.keycode! = 13)) {
$autocomplete. empty ();
var $SerTxt = $ ("#box4"). Val (). toLowerCase ();

if ($SerTxt! = "" && $SerTxt! = null) {
for (var k = 0; k < arry.length; k++) {
if (Arry[k].tolowercase (). IndexOf ($SERTXT) >= 0) {
$ ("<li title=" + arry[k] + "class=" + classname + "></li>"). Text (Arry[k]). AppendTo ($autocomplete). mouseover (function () {
$ (". AutoComplete li"). Removeclass ("hovers");
$ (this). CSS ({
Background: "#3368c4",
Color: "#fff"
})
}). mouseout (function () {
$ (this). CSS ({
Background: "#fff",
Color: "#000"
})
}). Click (function () {
$ ("#box4"). Val ($ (this). text ());
$autocomplete. Hide ()
})
}
}
}
$autocomplete. Show ()
}
var listsize = $ (". AutoComplete li"). Size ();
$ (". AutoComplete li"). EQ (0). addclass ("hovers");
if (Event.keycode = = 38) {
if (Cus < 1) {
cus = listsize-1;
$ (". AutoComplete li"). Removeclass ();
$ (". AutoComplete li"). EQ (cus). addclass ("hovers");
var text = $ (". AutoComplete li"). EQ (cus). text ();
$ ("#box4"). Val (text)
} else {
cus--;
$ (". AutoComplete li"). Removeclass ();
$ (". AutoComplete li"). EQ (cus). addclass ("hovers");
var text = $ (". AutoComplete li"). EQ (cus). text ();
$ ("#box4"). Val (text)
}
}
if (Event.keycode = = 40) {
if (Cus < (listsize-1)) {
cus++;
$ (". AutoComplete li"). Removeclass ();
$ (". AutoComplete li"). EQ (cus). addclass ("hovers");
var text = $ (". AutoComplete li"). EQ (cus). text ();
$ ("#box4"). Val (text)
} else {
cus = 0;
$ (". AutoComplete li"). Removeclass ();
$ (". AutoComplete li"). EQ (cus). addclass ("hovers");
var text = $ (". AutoComplete li"). EQ (cus). text ();
$ ("#box4"). Val (text)
}
}
if (Event.keycode = = 13) {
$ (". AutoComplete li"). Removeclass ();
$ ("#HTML"). HTML ("You have selected <font color= ' red ' >" + $ (". AutoComplete li"). EQ (cus). Text () + "</font>");
$autocomplete. Hide ();

}
}). blur (function () {
SetTimeout (function () {
$autocomplete. Hide ()
},
3000)
})
});
function SetValue (index) {
var DDL = document.getElementById ("HoHo");
var Value = Ddl.options[index].text;
document.getElementById ("Box4"). Value = value
$ ("#HTML"). HTML ("You have selected <font color= ' red ' >" +value+ "</font>");
}
</script>
<style>
. hoho{width:197;height:20px!important; height:17px;margin-left:-180px!important; margin-left:-179px}
. Sp{margin-left:179px;width:18px;overflow:hidden;}
. bo4{width:178px;position:absolute;left:0px!important;height:20px!important;top:0.5px!important; left:1px; top:0 px height:20px}
. autocomplete{list-style-type:none; margin:0px; padding:0px; border: #008080 1px solid}
. autocomplete li{font-size:12px; font-family: "Lucida Console", Monaco, monospace; font-weight:bold; cursor:pointer; height:20px; line-height:20px}
. hovers{Background-color: #3368c4; COLOR:FFF}
</style>

<BODY>
<table width= "border=" 0 "align=" center ">
<tr>
<td><div style= "position:relative;" >
<span class= "SP" >
<select id= "HoHo" name= "HoHo" class= "HoHo" onchange= "SetValue (this.selectedindex)" >
<option>=== Please select ===</option>
<option value= ' 0 ' >java ee</option>
<option value= ' 1 ' >java se</option>
<option value= ' 2 ' >java me</option>
<option value= ' 3 ' >Net</option>
<option value= ' 4 ' >PHP</option>
<option value= ' 5 ' >Ajax</option>
<option value= ' 6 ' >JQuer</option>
<option value= ' 6 ' > Principal 1123123</option>
<option value= ' 6 ' > Principal jqsdfuer</option>
<option value= ' 6 ' > Principal 3asdfjasdfquer</option>
<option value= ' 6 ' > Principal a23sdfsajquer</option>
<option value= ' 6 ' > Principal j232quer</option>
</select>

</span>
<input name= "box4" id= "box4" value= "= = = Please select = = =" class= "Bo4" >
</div>
</td>
&LT;TD id= "HTML" width= "B" > Input a try </td>
</tr>
</table>
</BODY>

jquery implementation Select drop-down box can input + Lenovo associated option

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.