asp查詢xml的程式碼不會刷新頁面查詢的實作方法以下為引用的內容:
<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>
用ASP的instr()函數來偵測字串中是否含有指定字串
<%
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函數
--------------------
InStr([start, ]string1, string2[, compare])
【參數】
InStr 函數的語法具有下面的參數:
部分
說明
start
可選參數。為數值表達式,設定每次搜尋的起點。如果省略,將從第一個字元的位置開始。如果start 包含Null,將會發生錯誤。如果指定了compare 參數,則一定要有start 參數。
string1
必要參數。接受搜尋的字串表達式。
string2
必要參數。被搜尋的字串表達式。
Compare
可選參數。指定字串比較。如果compare 是Null,將會發生錯誤。如果省略compare,Option Compare 的設定將決定比較的類型。
?compare 參數設定為:
常數
值
【描述】
vbUseCompareOption
-1
使用Option Compare 語句設定執行一個比較。
vbBinaryCompare
0
執行一個二進制比較。
vbTextCompare
1
執行一個依照原文的比較。
vbDatabaseCompare
2
僅適用於Microsoft Access,執行一個基於資料庫中資訊的比較。
【回傳值】
返回0、1、2、-1或Null等。
【異常/錯誤】
無
描述InStr([start, ]string1, string2[, compare])
傳回指定一字串在另一字串中最先出現的位置。在字串string1中,從start開始找string2,省略start時從string1頭開始找。找不到時,函數值為0。
如果
InStr返回
string1 為零長度
0
string1 為Null
Null
string2 為零長度
Start
string2 為Null
Null
string2 找不到
0
在string1 中找到string2
找到的位置
start > string2
0
【範例】
本範例使用InStr 函數來尋找某一字串在另一個字串中首次出現的位置。
Dim SearchString, SearchChar, MyPos
SearchString =XXpXXpXXPXXP ' 被搜尋的字串。
SearchChar = P ' 要找字串P。
' 從第四個字元開始,以文字比較的方式找起。傳回值為6(小寫p)。
' 小寫p 和大寫P 在文字比較下是一樣的。
MyPos = Instr(4, SearchString, SearchChar, 1)
' 從第一個字元開使,以二進位比較的方式找起。傳回值為9(大寫P)。
' 小寫p 和大寫P 在二進位比較下是不一樣的。
MyPos = Instr(1, SearchString, SearchChar, 0)
' 缺省的比對方式為二進位比較(最後一個參數可省略)。
MyPos = Instr(SearchString, SearchChar) ' 回傳9。
MyPos = Instr(1, SearchString, W) ' 回傳0。