手机
当前位置:查字典教程网 >编程开发 >ASP教程 >asp查询xml的代码 不刷新页面查询的方法
asp查询xml的代码 不刷新页面查询的方法
摘要:以下为引用的内容:不刷新页面查询的方法functionloadinsel(){varemployeeid,employeelastname;...

以下为引用的内容:

<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="查找">

</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。

【asp查询xml的代码 不刷新页面查询的方法】相关文章:

ASP中七种实现分页显示的方法

网页木马代码例子(里面的文件是漏洞扫描器,呵呵)

解决ASP(图像)上传漏洞的方法

asp实现防止站外提交内容的两个方法

一种理论上最快的Web数据库分页方法

aspjpeg组件使用方法

asp中正则表达式过滤html代码函数

代码与页面的分离

asp 查询数据代码

用asp实现的代码批量修改程序,fso相关

精品推荐
分类导航