日期:2011-07-30 浏览次数:21087 次
<html>
<head>
<title>不刷新页面查询的方法</title>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312">
</head>
<scriptlanguage="javascript">
functionsearch_onclick(){
file://得到筛选雇员的名字
searchtext=window.searchContent.value
file://首先移除在所有查询结果列表中的选项
j=searchObj.length;
for(i=j-1;i>=0;i--)
{
searchObj.remove(i);
}
if(searchtext!=""){
file://显示符合筛选条件的雇员
j=searchSource.length;
for(i=0;i<j;i++){
searchsource=searchSource.options(i).text;
k=searchsource.indexOf(searchtext);
if(k!=-1){
option1=document.createElement("option");
option1.text=searchsource;
option1.value=searchSource.options(i).value;
searchObj.add(option1);
}
}
}
else{
file://如果没有输入查询条件则显示所有雇员
j=searchSource.length;
for(i=0;i<j;i++){
searchsource=searchSource.options(i).text;
option1=document.createElement("option");
option1.text=searchsource;
option1.value=searchSource.options(i).value;
searchObj.add(option1);
}
}
}
</script>
<bodybgcolor="#FFFFFF"text="#000000">
<%
servername="wyb"'服务器名
user="sa"'用户名
pw=""'用户密码
databasename="northwind"'数据库名
setconn=server.CreateObject("adodb.connection")
conn.Open"DRIVER=SQLServer;SERVER="&servername&";UID="&user&";pwd="&pw&";DATABASE="& databasename
setrs=server.CreateObject("adodb.recordset")
sql="Selectemployeeid,lastnamefromemployeesorderbyemployeeid"
rs.Opensql,conn%>
<tablewidth="80%"border="1">
<tr>
<td>
<inputtype="text"name="searchContent">
<inputtype="button"name="Button"value="查 询">
</td>
</tr>
<tr>
<td>查询结果<br>
<selectname="searchObj"size="10">
<%dowhilenotrs.eof%>
<optionvalue="<%=rs("employeeid")%>"><%=rs("lastname")%></option>
<%rs.movenext
loop
%>
</select>
<selectname="searchSource"size="10"style="display:none">
<%
rs.movefirst
dowhilenotrs.eof%>
<optionvalue="<%=rs("employeeid")%>"><%=rs("lastname")%></option>
<%rs.movenext
loop
%>
</select>
</td>
</tr>
</table>
<%rs.close
setrs=nothing
%>
</body>
</html>