Menu_search. JSP code is as follows:
menu_search. JSP code
<% @ page language="Java"
Import="Java. Util. *, com. Findu. Entity. *, com. Findu. Dao. *, Java. Text. *, com. Findu. Service. *", "
ContentType="text/HTML. Charset=utf-8 "% & gt;
<%
String searchx=(String) request. GetAttribute (" search ");
If (searchx==null) {
Searchx="";
}
String typeNamex=(String) request. GetAttribute (" typeName ");
If (typeNamex==null) {
TypeNamex="";
}
%>
Var searchElement=document. GetElementById (" Search ");//get a search box
Var div=document. GetElementById (" context ");//get prompt box
SearchElement. Onkeyup=function () {//button up event
Value; var name=this.
//get the XHR object
Var XHR=getXMLHttpRequest ();
//process the results
XHR. Onreadystatechange=function () {
If (XHR. ReadyState==4) {
If (XHR. Status==200) {
Var STR=XHR. The responseText;
if (str ! {
="")Div. Style. The display="block";//show
} else {
Div. Style. The display="none";//show
}
Var ss=STR. The split (", ");
//var ss=eval (" (" + XHR. ResponseTest + ") ");
Var childDivs="";
For (var I=0; i
"Style=" font - weight: bold; Padding - left: 8 px; padding-top:5px; Padding - bottom: 5 px; '& gt;"
[I] + + ss "& lt;/div> ";//put each element in the div
}
Div. InnerHTML=childDivs;
}
}
}
XHR. Open (" get ", "/FindU/servlet/AJAXSearchServlet? Name="+ name);
XHR. Send (null);
}
}
The function changeBackground_over (div) {
Div. Style. BackgroundColor="# E8E8E8";
}
The function changeBackground_out (div) {
Div. Style. BackgroundColor="";
}
//filler text into the search box
The function writeText (div) {
//get prompt box
Var searchElement=document. GetElementById (" Search ");
SearchElement. Value=https://bbs.csdn.net/topics/div.innerHTML;
Div. ParentNode. Style. The display="none";//the prompt box hidden
}
//get the XMLHttpRequest object
The function getXMLHttpRequest () {
Var XMLHTTP;
If (window. The XMLHttpRequest) {//for IE7 +, Firefox, Chrome, Opera, Safari
XMLHTTP=new XMLHttpRequest ();
} else {//for IE6, IE5
XMLHTTP=new ActiveXObject (" Microsoft. XMLHTTP ");
}
Return the XMLHTTP;
}
The function hide () {
Var context=document. GetElementById (" context ");
Context. Style. The display="none";//the prompt box hidden
}
</script>