asp查询xml的代码实现无刷新 模糊查询

来源:新云 时间:2008-04-30 15:39:00 



<html>
<head>
<title>不刷新页面查询的方法</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<script language="javascript">
<!--初始化,将数据岛中数据装入列表框中-->
function loadinsel()
{
var employeeid,employeelastname;          //分别存放雇员ID和雇员名字
root=document.all.xmlemployees.childNodes.item(0); //返回第一个元素--employee
for(i=0;i<root.childNodes.length;i++){
 getnode=root.childNodes(i);            //得到empolyee的一个子节点
employeeid=root.childNodes(i).getAttribute("emid");//得到雇员ID
for(j=0;j<getnode.childNodes.length;j++){
employeeinf=getnode.childNodes(j).nodeName;
if(employeeinf=="lastname"){
employeelastname=getnode.childNodes(j).text; //得到雇员名字
}
}
//将得到的employeeid和employeelastname写进select中
if(employeeid!="" && employeelastname!=""){
option1=document.createElement("option");
option1.text=employeelastname;
option1.value=employeeid;
employeelist.add(option1);
}
}
}

<!--初始化,从数据岛中检索数据,装入列表框中-->
function findemployee(){
var employeelastname,employeeid;               //分别存放雇员名字和雇员ID
employeelastname="";
employeeid="";
findtext=window.findcontent.value;              //得到检索条件
//清除列表框
employeecount=employeelist.length
for(i=employeecount-1;i>=0;i--){
employeelist.remove(i);
}
root=window.xmlemployees.childNodes(0);
for(i=0;i<root.childNodes.length;i++){
getitem=root.childNodes(i);                //得到empolyee的一个子节点
employeeid=root.childNodes(i).getAttribute("emid");    //得到雇员ID
for(j=0;j<getitem.childNodes.length;j++){
if(getitem.childNodes(j).nodeName=="lastname"){
employee_temp=getitem.childNodes(j).text;
if(employee_temp.indexOf(findtext)!=-1){      //查找匹配项
employeelastname=employee_temp;         //找到名字匹配的雇员
}

}

}
//将符合条件的雇员信息写进select中
if(employeeid!="" && employeelastname!=""){
option1=document.createElement("option");
option1.value=employeeid;
option1.text=employeelastname;
window.employeelist.add(option1);
employeeid="";
employeelastname="";
}
}
}
</script>
<body bgcolor="#FFFFFF" text="#000000" onload="javascript:loadinsel()">
<table width="80%" border="1">
<tr>
<td> 请输入查询条件:
<input type="text" name="findcontent">
<input type="button" name="Submit" value="查找" onclick="javascript:findemployee()">
</td>
</tr>
<tr>
<td> 查询结果:
<select name="employeelist">
</select>
</td>
</tr>
</table>
<?xml version="1.0" encoding="gb2312"?>
<%
servername="wyb" '服务器名
user="sa" '用户名
pw="" '用户密码
databasename="northwind" '数据库名
set conn=server.CreateObject("adodb.connection")
conn.Open "DRIVER=SQL Server;SERVER="&servername&";UID="&user&";pwd="&pw&";DATABASE="&databasename
set rs=server.CreateObject("adodb.recordset")
sql="Select employeeid,lastname from employees order by employeeid"
rs.Open sql,conn%>
<!--将数据库中信息放入数据岛中-->
<xml id="xmlemployees">
<employee>
<%do while not rs.eof%>
<employeeitem emid="<%=rs("employeeid")%>">
  <lastname><%=rs("lastname")%></lastname>
</employeeitem>
<%rs.movenext%>
<%loop%>
</employee> </xml>
<%rs.close
set rs=nothing
%>
</body>
</html>


标签:
0
投稿

猜你喜欢

  • JavaScript/jQuery实现切换页面效果

    2024-04-22 22:23:17
  • Javascript中Math.max和Math.max.apply的区别和用法详解

    2024-04-10 10:55:04
  • 使用php操作xml教程

    2023-06-14 03:10:45
  • 在Python中使用异步Socket编程性能测试

    2023-04-20 23:19:56
  • Python实现特定场景去除高光算法详解

    2021-11-16 09:50:03
  • Python使用openpyxl复制整张sheet

    2023-11-21 23:09:18
  • 全国哀悼日 建议站点换素装(附代码)

    2008-05-19 12:05:00
  • Python DataFrame.groupby()聚合函数,分组级运算

    2022-02-08 07:23:09
  • python3.x上post发送json数据

    2021-07-03 02:07:23
  • 微信小程序开发之实现心情记事本

    2024-04-18 09:45:20
  • python 在服务器上调用数据库特别慢的解决过程

    2024-01-19 11:40:20
  • Go语言中int、float、string类型之间相互的转换

    2024-02-03 04:32:55
  • 使用FCKeditor添加文章时,在文章最后多了逗号

    2007-10-11 13:38:00
  • PyTorch实现AlexNet示例

    2021-08-31 20:15:44
  • Django框架基础认证模块auth应用示例

    2023-11-10 07:48:51
  • Python configparser模块应用过程解析

    2022-08-03 19:56:11
  • python Flask框架之HTTP请求详解

    2023-10-02 01:52:55
  • 如何解决ORA-01843与NLS_DATE_FORMAT问题

    2023-06-30 20:57:14
  • 详解CentOS 6.5中安装mysql 5.7.16 linux glibc2.5 x86 64(推荐)

    2024-01-15 19:01:11
  • 分别用两个函数实现的菜单

    2024-04-19 10:05:36
  • asp之家 网络编程 m.aspxhome.com