ASP常用代码段之九
1:asp联动三级菜单
<!--#include file="Conn.asp"-->
<%
sql = "select * from smallclass order by smallclassid asc"
set rs = conn.execute(sql)
%>
<script language = "JavaScript">
var onecount;
onecount=0;
subcat = new Array();
<%
count = 0
do while not rs.eof
%>
subcat[<%=count%>] = new Array("<%= trim(rs("smallclassname"))%>","<%= trim(rs("bigclassname"))%>","<%= trim(rs("smallclassname"))%>");
<%
count = count + 1
rs.movenext
loop
rs.close
set rs=nothing
%>
onecount=<%=count%>;
function changelocation(bigclassname)
{
document.myform.smallclassname.length = 0;
var bigclassname=bigclassname;
var i;
document.myform.smallclassname.options[0] = new Option('请选择二级分类','');
for (i=0;i < onecount; i++)
{
if (subcat[i][1] == bigclassname)
{
document.myform.smallclassname.options[document.myform.smallclassname.length] = new Option(subcat[i][0], subcat[i][2]);
}
}
}
</script>
<%sql2 = "select * from minclass order by minclassid asc"
set rs2 = conn.execute(sql2)
%>
<script language = "JavaScript">
var onecount2;
onecount2=0;
subcat2 = new Array();
<%
count2 = 0
do while not rs2.eof
%>
subcat2[<%=count2%>] = new Array("<%= trim(rs2("minclassname"))%>","<%= trim(rs2("smallclassname"))%>","<%= trim(rs2("minclassname"))%>");
<%
count2 = count2 + 1
rs2.movenext
loop
rs2.close
set rs2=nothing
%>
onecount2=<%=count2%>;
function changelocation2(smallclassname)
{
document.myform.minclassname.length = 0;
var smallclassname=smallclassname;
var j;
document.myform.minclassname.options[0] = new Option('请选择三级分类','');
for (j=0;j < onecount2; j++)
{
if (subcat2[j][1] == smallclassname)
{
document.myform.minclassname.options[document.myform.minclassname.length] = new Option(subcat2[j][0], subcat2[j][2]);
}
}
}
</script>
<body onLoad="javascipt:setTimeout('loadForm()',1000);">
<form method="POST" name="myform" onSubmit="return CheckForm();" action="ArticleSave.asp?action=add" target="_self">
<table width="620" border="0" align="center" cellpadding="0" cellspacing="0" class="border">
<tr align="center">
<td class="tdbg"> <table width="100%" border="0" cellpadding="0" cellspacing="2">
<tr>
<td width="151" height="22" align="right" bgcolor="#C0C0C0">所属类别:</td>
<td width="467" bgcolor="#E3E3E3">
<select name="bigclassname" onChange="changelocation(document.myform.bigclassname.options[document.myform.bigclassname.selectedIndex].value)" size="1">
<option selected>请选择一级分类</option>
<%
sql1 = "select * from bigclass order by bigclassid asc"
set rs1 = conn.Execute (sql1)
do while not rs1.eof
%>
<option value="<%=trim(rs1("bigclassname"))%>"><%=trim(rs1("bigclassname"))%></option>
<%
rs1.movenext
loop
rs1.close
set rs1 = nothing
conn.Close
set conn = nothing
%>
</select>
<select name="smallclassname" onChange="changelocation2(document.myform.smallclassname.options[document.myform.smallclassname.selectedIndex].value)">
<option selected value="">==所有二级分类==</option>
</select>
<select name="minclassname" size="1">
<option selected value="">==所有三级分类==</option>
</select> </td>
</tr>
</table></td>
</tr>
</table>
</form>
表结构如下
BIGCLASS: bigclassid,bigclassname,
smallclass smallclassid ,bigclassname,smallclassname
minclass minclassid,bigclassname,smallclassname,minclassname.
2:asp统计中文混合的字符串长度
strCount(strString)
Ortototo
3:asp截取指定长度的字符串
0or
4:asp检查组件是否已经安装
errorresume0
5:asp检查Email地址合法性
'********************************************
'函数名:BPCheckEMail
'作 用:检查Email地址合法性
'参 数:email ----要检查的Email地址
'返回值:True ----Email地址合法 False ----Email地址不合法
'********************************************
Function BPCheckEMail(email)
Dim strArr,strRE1,strRE2,oRE1,oRE2,oMatches1,oMatches2
strArr = Split(email,"@")
If UBound(strArr) <> 1 Then
BPCheckEMail = False : Exit Function
End If
strRE1 = "^(?:[\w\.-]+@[A-Za-z1-9]{1}[A-Za-z0-9\.-]+\.[A-Za-z1-9]{2,3})"
strRE2 = "[^\w\.@:-]+"
Set oRE1 = New RegExp : Set oRE2 = New RegExp
oRE1.Pattern = strRE1 : oRE2.Pattern = strRE2
oRE1.IgnoreCase = False : oRE2.IgnoreCase = False
oRE1.Global = True : oRE2.Global = True
Set oMatches1 = oRE1.Execute(email) : Set oMatches2 = oRE2.Execute(email)
If oMatches1.Count <> 0 And oMatches2.Count = 0 Then
BPCheckEMail = True
Else
BPCheckEMail = False
End If
End Function
6: asp生成指定类型的随机字符串
CaseCase
7:asp取得某个网页的内容
then
exitthen
err.Clear
end
8:asp的验证码
-9999
Response.AddHeader
Response.ContentType =0To
vNumberData(
vNumberData(
vNumberData(
vNumberData(
vNumberData(9To0To1ToRnd*99+110""if