asp查询xml的代码 不刷新页面查询的方法
来源:asp之家 发布时间:2011-04-06 11:00: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> 用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。
猜你喜欢
- 在线阅读与印刷品阅读有着很大的不同,原因之一是屏幕会导致注意力问题。文字很难成为重点,而闪烁的横幅、明亮的图片又更加会转移对实际的博客内容的
- pyx文件是python的c扩展文件,代码要符合cython的规范,用什么编辑器写都行。我在eric4上写的,结果它默认用python解释器
- pymsql是Python中操作MySQL的模块,其使用方法和MySQLdb几乎相同。但目前pymysql支持python3.x而后者不支持
- 最近开始学机器学习,学习分析垃圾邮件,其中有一部分是要求去除一段字符中的标点符号,查了一下,网上的大多很复杂例如这样import re te
- 业务场景:前后端分离需要对接数据接口。接口测试是在postman做的,今天才开始和前端对接,由于这是我第一次做后端接口开发(第一次嘛,问题比
- 安装MySQL ODBC驱动官方说法:MySQL ODBC 驱动程序负责在开放式数据库连接 API (ODBC API) 的帮助下访问 My
- 一、 yaml1、 准备支持的数据类型:字典、列表、字符串、布尔值、整数、浮点数、Null、时间等基本语法规则:大小写敏感使用缩进表示层级关
- 如下代码会将npy的格式数据读出,并且输出来到控制台:import numpy as np##设置全部数据,不输出省略号 import sy
- RSA算法RSA算法是一种公钥加密技术,被认为是最安全的加密方式.它是由Rivest,Shamir和Adleman于1978年发明的,因此命
- 本文主要是关于matplotlib的一些基本用法。Demoimport matplotlib.pyplot as pltimport num
- 我们需要开始思考如何将文本集合转化为可量化的东西。最简单的方法是考虑词频。我将尽量尝试不使用NLTK和Scikits-Learn包。我们首先
- 本文实例讲述了JS实现获取数组中最大值或最小值功能。分享给大家供大家参考,具体如下:方法一://最小值Array.prototype.min
- Edit:2016-5-11 修正了代码里面一些明显的错误,并发布在 ajaxjs 库之中,源码在这里。Edit:2016-5-24 加入
- 神经网络模型一般用来做分类,回归预测模型不常见,本文基于一个用来分类的BP神经网络,对它进行修改,实现了一个回归模型,用来做室内定位。模型主
- 本文详述了Python的import机制,对于理解Python的运行机制很有帮助!1.标准import:Python中所有加载到内存的模块都
- Function ChkInvaildWord(Words) Const InvaildWords=&quo
- 往期学习:python数据类型: python数据结构:数据类型.python的输入输出: python数据结构之输入输出及控制和异常.py
- 一、前言图像拼接技术就是将数张有重叠部分的图像(可能是不同时间、不同视角或者不同传感器获得的)拼成一幅无缝的全景图或高分辨率图像的技术。二、
- 直方图处理直方图从图像内部灰度级的角度对图像进行表述从直方图的角度对图像进行处理,可以达到增强图像显示效果的目的。直方图的含义直方图是图像内
- Python 面向对象方法没有重载#在其他语言中,可以定义多个重名的方法,只要保证方法签名唯一即可。方法签名包含3个部分:方法名、参数数量、