明輝手游網(wǎng)中心:是一個(gè)免費(fèi)提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺(tái)!

asp查詢xml的代碼,完成了無刷新、含糊查詢技巧

[摘要]<html><head><title>不刷新頁面查詢的方法</title><meta http-equiv="Content-Type" content="text/html; charset=gb2312&quo...

<html>
<head>
<title>不刷新頁面查詢的方法</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<script language="javascript">
<!--初始化,將數(shù)據(jù)島中數(shù)據(jù)裝入列表框中-->
 function loadinsel()
 {
   var employeeid,employeelastname;          //分別存放雇員ID和雇員名字
   root=document.all.xmlemployees.childNodes.item(0);  //返回第一個(gè)元素--employee
   for(i=0;i<root.childNodes.length;i++){
    getnode=root.childNodes(i);             //得到empolyee的一個(gè)子節(jié)點(diǎn)
     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寫進(jìn)select中
  if(employeeid!="" && employeelastname!=""){
  option1=document.createElement("option");
  option1.text=employeelastname;
  option1.value=employeeid;
  employeelist.add(option1);
  } 
   }
 }
 
 <!--初始化,從數(shù)據(jù)島中檢索數(shù)據(jù),裝入列表框中-->
 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的一個(gè)子節(jié)點(diǎn)
   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){  //查找匹配項(xiàng)
        employeelastname=employee_temp;     //找到名字匹配的雇員
     }
    
    }

       }
 //將符合條件的雇員信息寫進(jìn)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> 請(qǐng)輸入查詢條件:
<input type="text" name="findcontent">
      <input type="button" name="Submit" value="查找" onclick="javascript:findemployee()">
    </td>
  </tr>
  <tr>
    <td> 查詢結(jié)果:
<select name="employeelist">
      </select>
    </td>
  </tr>
</table>
<?xml version="1.0" encoding="gb2312"?>
<%
  servername="wyb"            '服務(wù)器名
  user="sa"                   '用戶名         
  pw=""                       '用戶密碼
  databasename="northwind"    '數(shù)據(jù)庫名
  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%>
 <!--將數(shù)據(jù)庫中信息放入數(shù)據(jù)島中-->
<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>