This code was born as follows:
CopyCode The Code is as follows: <HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> No title page </title>
<SCRIPT type = "text/JavaScript" Language = "JavaScript">
VaR currentindex =-1; // Save the index selected in the prompt box
VaR sumsearchcount = 0; // number of data in the SAVE prompt box
VaR tempvalue = ""; // Save the content to be searched
VaR objtxt = ""; // Save the text box object
VaR Top = 0; // top of the prompt box
VaR left = 0; // left of the prompt box
VaR width = 0; // The width of the prompt box
VaR values = new array (); // Save the value of the drop-down list
VaR texts = new array (); // Save the content displayed in the drop-down list
VaR tempdiv = new array (); // Save the values index corresponding to the index in the prompt box
// Obtain the value and display content of the drop-down list
Function getselectvalues (DDL ){
Ddlvalue = Document. getelementbyid ("dropdownlist1 ");
For (VAR I = 0; I <ddlvalue. length; I ++ ){
Values [I] = ddlvalue. Options [I]. value;
Texts [I] = ddlvalue. Options [I]. text;
}
}
VaR ointerval = ""; // Save the automatic timer object
Function fnstartinterval (txt_id ){
Getselectvalues ("dropdownlist1 ");
Objtxt = txt_id; // obtain the object of the input text box
Top = getlength ("offsettop") + objtxt. offsetheight;
Left = getlength ("offsetleft ");
Width = objtxt. offsetwidth;
Ointerval = Window. setinterval ("beginsearch ()", 2000); // enable timing
}
// Obtain the length of the corresponding attribute
Function getlength (attribute)
{
VaR offset = 0;
VaR txt_input = Document. getelementbyid ("txtsearch ");
While (item)
{
Offset + = txt_input [attribute];
Txt_input = txt_input.offsetparent;
}
Return offset;
}
// Stop timing
Function fnstopinterval ()
{
Window. clearinterval (ointerval );
}
// Automatic completion prompt
Function beginsearch (){
If (objtxt. value. length> 0 & tempvalue! = Objtxt. value)
{
Sumsearchcount = 0;
Tempvalue = objtxt. value;
VaR div_show = Document. getelementbyid ("divmsg ");
Div_show.style.top = Top + "PX ";
Div_show.style.display = "Block ";
Div_show.style.left = left + "PX ";
Div_show.style.width = width + "PX ";
Div_show.innerhtml = "";
VaR Leng = texts. length;
VaR txt_value = objtxt. value;
VaR ROW = "";
For (VAR I = 0; I <Leng; I ++ ){
If (texts [I]. indexof (txt_value )! =-1 ){
Row = row + "<Div style = \" font-size: 14px; display: block; width: 100% \ "id = 'divsearch _" + I + "'onmouseover = \" this. style. backgroundcolor = '# 3366cc'; currentindex = "+ I +"; \ "onmouseout = \" this. style. backgroundcolor = ''; currentindex =-1; \" onclick = \ "span_click (this) \"> "+ texts [I] +" </div> ";
Tempdiv [sumsearchcount] = I;
Sumsearchcount ++;
}
}
Div_show.innerhtml = row;
}
Else if (objtxt. value. Length = 0 | objtxt. value = NULL)
{
VaR div_msg = Document. getelementbyid ("divmsg ");
Div_msg.style.display = "NONE ";
Div_msg.innerhtml = "";
}
}
// Click Save to text box for the prompt content
Function span_click (SP)
{
Clear ();
Objtxt. value = sp. innerhtml;
Document. getelementbyid ("dropdownlist1 "). options [Sp. id. substring (sp. id. indexof ('_') + 1, SP. id. length)]. selected = "selected ";
}
// Stop the query and close the prompt
Function closesearch ()
{
VaR TBL = Document. activeelement. parentelement;
If (TBL & TBL. ID! = "Divmsg") // prevents missing prompts after the upper/lower keys are used
{
Clear ();
Document. getelementbyid ("divmsg"). innerhtml = "";
}
Else if (currentindex =-1)
{
Clear ();
Document. getelementbyid ("divmsg"). innerhtml = "";
}
}
// Empty prompt
Function clear ()
{
Fnstopinterval ();
Currentindex =-1;
Tempvalue = "";
Document. getelementbyid ("divmsg"). style. Display = "NONE ";
}
// Use the keyboard's up and down arrow keys and enter keys
Function changeselect ()
{
VaR divcontent = Document. getelementbyid ("divmsg ");
If (divcontent & divcontent. style. Display = "Block ")
{
If (event. keycode = 38 | event. keycode = 40 | event. keycode = 13)
{
If (currentindex! =-1) document. getelementbyid ("divsearch _" + tempdiv [currentindex]). style. backgroundcolor = "";
If (event. keycode = 38 & currentindex> 0)
{
Currentindex --;
Document. getelementbyid ("divsearch _" + tempdiv [currentindex]). style. backgroundcolor = "# 3366cc ";
}
Else if (event. keycode = 40 & currentindex <sumSearchCount-1)
{
Currentindex ++;
Document. getelementbyid ("divsearch _" + tempdiv [currentindex]). style. backgroundcolor = "# 3366cc ";
}
Else if (event. keycode = 13)
{
If (currentindex>-1)
{
VaR divpart = Document. getelementbyid ("divsearch _" + tempdiv [currentindex]);
Objtxt. value = divpart. innerhtml;
Document. getelementbyid ("dropdownlist1"). Options [tempdiv [currentindex]. Selected = "selected ";
Clear ();
}
}
}
}
}
</SCRIPT>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>
<Input type = "text" id = "txtsearch" AutoComplete = "off" onkeydown = "changeselect ()" onfocus = "fnstartinterval (this)" onblur = "closesearch () "runat =" server "/>
<Asp: dropdownlist id = "dropdownlist1" runat = "server" datatextfield = "slr_realname" datavaluefield = "systemloginrecord_id" datasourceid = "objectdatasource1" width = "130px">
</ASP: dropdownlist> <asp: objectdatasource id = "objectperformance1" runat = "server" selectmethod = "getrecordds"
Typename = "testdal"> </ASP: objectdatasource>
</Div>
<Div style = "display: none; Z-index: 2; text-align: Left; position: absolute; Border: solid 1px;" id = "divmsg">
</Div>
</Form>
</Body>
</Html>
<Input type = "text" id = "txtsearch" AutoComplete = "off "... The AutoComplete attribute is added here to block the prompt function of text box input records. Although this function is good, it becomes a stumbling block here. Haha
I have no habit of writing a blog before. I forget a lot of things that I don't often use. It will be sorted out later.