主頁 > 知識庫 > asp查詢xml的代碼 不刷新頁面查詢的方法

asp查詢xml的代碼 不刷新頁面查詢的方法

熱門標(biāo)簽:服務(wù)器配置 Mysql連接數(shù)設(shè)置 阿里云 科大訊飛語音識別系統(tǒng) 團(tuán)購網(wǎng)站 電子圍欄 Linux服務(wù)器 銀行業(yè)務(wù)
以下為引用的內(nèi)容:
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); //返回第一個元素--employee
for(i=0;iroot.childNodes.length;i++){
 getnode=root.childNodes(i);            //得到empolyee的一個子節(jié)點
employeeid=root.childNodes(i).getAttribute("emid");//得到雇員ID
for(j=0;jgetnode.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;iroot.childNodes.length;i++){
getitem=root.childNodes(i);                //得到empolyee的一個子節(jié)點
employeeid=root.childNodes(i).getAttribute("emid");    //得到雇員ID
for(j=0;jgetitem.childNodes.length;j++){
if(getitem.childNodes(j).nodeName=="lastname"){
employee_temp=getitem.childNodes(j).text;
if(employee_temp.indexOf(findtext)!=-1){      //查找匹配項
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> 請輸入查詢條件:
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>
用ASP的instr()函數(shù)來檢測字符串中是否含有指定字符串
%
Dim wstr1,wstr2
wstr1="hello world!"
wstr2="o"
if instr(wstr1,wstr2)>0 then
response.write(" "wstr1"中存在"wstr2" ")
else
response.write(" "wstr1"中不包含有"wstr2" ")
end if
%>
--------------------
InStr函數(shù)
--------------------
InStr([start, ]string1, string2[, compare])
【參數(shù)】
InStr 函數(shù)的語法具有下面的參數(shù):
部分
說明
start
可選參數(shù)。為數(shù)值表達(dá)式,設(shè)置每次搜索的起點。如果省略,將從第一個字符的位置開始。如果 start 包含 Null,將發(fā)生錯誤。如果指定了 compare 參數(shù),則一定要有 start 參數(shù)。
string1
必要參數(shù)。接受搜索的字符串表達(dá)式。
string2
必要參數(shù)。被搜索的字符串表達(dá)式。
Compare
可選參數(shù)。指定字符串比較。如果 compare 是 Null,將發(fā)生錯誤。如果省略 compare,Option Compare 的設(shè)置將決定比較的類型。
?compare 參數(shù)設(shè)置為:
常數(shù)

【描述】
vbUseCompareOption
-1
使用Option Compare 語句設(shè)置執(zhí)行一個比較。
vbBinaryCompare
0
執(zhí)行一個二進(jìn)制比較。
vbTextCompare
1
執(zhí)行一個按照原文的比較。
vbDatabaseCompare
2
僅適用于Microsoft Access,執(zhí)行一個基于數(shù)據(jù)庫中信息的比較。
【返回值】
返回0、1、2、-1或Null等。
【異常/錯誤】

描述InStr([start, ]string1, string2[, compare])
返回指定一字符串在另一字符串中最先出現(xiàn)的位置。在字符串string1中,從start開始找string2,省略start時從string1頭開始找。找不到時,函數(shù)值為0。
如果
InStr返回
string1 為零長度
0
string1 為 Null
Null
string2 為零長度
Start
string2 為 Null
Null
string2 找不到
0
在 string1 中找到string2
找到的位置
start > string2
0
【示例】
本示例使用 InStr 函數(shù)來查找某字符串在另一個字符串中首次出現(xiàn)的位置。
Dim SearchString, SearchChar, MyPos
SearchString ="XXpXXpXXPXXP" ' 被搜索的字符串。
SearchChar = "P" ' 要查找字符串 "P"。
' 從第四個字符開始,以文本比較的方式找起。返回值為 6(小寫 p)。
' 小寫 p 和大寫 P 在文本比較下是一樣的。
MyPos = Instr(4, SearchString, SearchChar, 1)
' 從第一個字符開使,以二進(jìn)制比較的方式找起。返回值為 9(大寫 P)。
' 小寫 p 和大寫 P 在二進(jìn)制比較下是不一樣的。
MyPos = Instr(1, SearchString, SearchChar, 0)
' 缺省的比對方式為二進(jìn)制比較(最后一個參數(shù)可省略)。
MyPos = Instr(SearchString, SearchChar) ' 返回 9。
MyPos = Instr(1, SearchString, "W") ' 返回 0。
您可能感興趣的文章:
  • 用js實現(xiàn)QQ在線查詢功能
  • asp.net連接數(shù)據(jù)庫 增加,修改,刪除,查詢代碼
  • asp.net IList查詢數(shù)據(jù)后格式化數(shù)據(jù)再綁定控件
  • asp.net 網(wǎng)頁動態(tài)查詢條件的實現(xiàn)
  • asp.net中g(shù)ridview的查詢、分頁、編輯更新、刪除的實例代碼
  • ASP多條件查詢功能實現(xiàn)代碼(多關(guān)鍵詞查詢)
  • 基于ASP實現(xiàn)QQ在線查詢功能

標(biāo)簽:蚌埠 衢州 衡水 大理 棗莊 萍鄉(xiāng) 廣元 江蘇

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《asp查詢xml的代碼 不刷新頁面查詢的方法》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266