对于每个选项都有一个对应的ID,当选择某一项,应该能读它的ID.
解决方案 »
- Jquery ZTREE问题求教
- 如何用js实现动态画数据关系图?
- 用javascript读取xml、DTD
- 怎么编程实现然IE的编码设置成自动选择阿?
- Effect.Transitions = {}与Effect.Base.prototype = {n:1,m:"mm"}
- 求一Javascript问题
- 弹出窗体和原窗体的布局问题!
- 如何用dhtml、javascript实现excel的功能:纵坐标和横坐标的标题栏固定在一个地方,而纵横坐标的内容可以随滚动条的滚动而滚动?
- 用超级链接提交表单如何通过检验?
- script里是看不懂的乱码,该如何解决?
- 关于Onkeypress和keydown
- 关于事件
如果是就用AJAX读取后台返回给前台
下拉列表的数据需要用Ajax来动态获取,由textbox的onchange时间触发
只要好不好看,当然要靠HTML和CSS咯
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<style>
<!--
body{font-size:12px;}
#show{border:1px solid #9abcde; line-height:23px; width:200px; margin:0px;}
#show li{list-style:none;}
#sug{margin:0px auto;}
.style1 {font-size: x-large}
-->
</style>
<script language="javascript">
<!--
var xmlHttp = false;
function ajaxcreate(){
try {xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e2) {
xmlHttp = false;
}
}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
xmlHttp = new XMLHttpRequest();
}
if(!xmlHttp){alert('Create Xmlhttp Fail ');return false;}
}
function sugguest(){
ajaxcreate();
var xmvalue=document.getElementById("key").value;
//var url="post.ASP?key="+encodeURI(xmvalue)+"&rnd="+Math.random();
var url="post.ASP?key="+(xmvalue)+"&rnd="+Math.random(1);
if (xmvalue== null || xmvalue.length>20 || xmvalue == "") return false;
xmlHttp.open("POST",url,true);
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlHttp.send(xmvalue);
xmlHttp.onreadystatechange=returnstate;
}
function returnstate(){
if(xmlHttp.readyState != 4 ){
document.getElementById("sug").innerHTML="plase wait....";
}
if(xmlHttp.readyState == 4 ){
document.getElementById("sug").innerHTML=xmlHttp.responseText;
}
}function fillin(str){
document.getElementById('key').value=str;
obj =document.getElementById('sug');
obj.innerHTML='';
obj.style.display='none';
}
function other(){
document.getElementById('sug').style.display='block';
}function losefouse(){
setInterval("func()",4000);
var time=setInterval("func()",1000);
clearTimeout(time);}function func(){
ob=document.getElementById('sug');
ob.style.display = 'none';
} -->
</script>
<body >
<table width="400" border="0" align="center" cellpadding="0" cellspacing="0">
<form name="form1" method="post" action=""><tr>
<td>
<input name="key" type="text" id="key" onFocus="other();" onKeyDown="sugguest();" onBlur="losefouse();" size="27" autocomplete=off >
<input type="submit" name="Submit" value="搜索">
</td>
</tr></form>
<tr>
<td ><div id="sug" onClick="javascript:func();"></div></td>
</tr>
</table>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
</body>
</html>
<%
Response.charset="GB2312"
sjbyDB="sjnews.mdb"
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(""&sjbyDB&"")
'On Error Resume Next
Set conn = Server.CreateObject("ADODB.Connection")
conn.open connstr
If Err Then
err.Clear
Set Conn = Nothing
Response.Write "数据库连接出错,请联系管理员。"'
Response.End
End If
key=Request.QueryString("key")
set rs = server.CreateObject ("adodb.recordset")
sql="select * from news where title like '%"&key&"%' order by id desc"
rs.open sql,conn,1,1
response.Write("<div id=show >")
if not rs.bof then
do while not rs.eof
response.Write("<li onMouseOver=""this.style.background='#d7ebff'"" onMouseOut=""this.style.background='#ffffff'"" onclick=""javascript:fillin(this.innerHTML);"">"&rs("title")&"</li>")
rs.movenext
loop
else
response.Write key
end if
response.Write("</div>")
%>