栏目导航
热点推荐
- ASP下批量删除数据的两种方法
- 关于二级域名共享cookies
- ASP错误代码大全
- ASP代码实现show.asp?id=26变成s
- ASP错误信息解决:IIS启用父路径
- 一些常用的正则表达式大全
- ASP超级链接和HTML函数正则表达
- ASP隐藏下载地址及防盗代码
- 最常用的正则表达式示例
- ASP程序数据库被挂马的处理方法
- ASP生成html的新方法
- 精通ASP错误提示大全
阅览排行
ASP常用代码段之九
www.jz123.cn 2010-09-29 来源: 中国建站 责任编辑(袁袁) 我要投递新闻
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统计中文混合的字符串长度
*************************************** '统计中文混合的字符串长度 '*************************************** function strCount(strString) Dim I,count if Trim(strString)="" Or IsNull(strString) then count=0 else count=0 for I=1 to Len(Trim(strString)) if Asc(Mid(strString,I,1))<0 then count=count+2 else count=count+1 end if next end if strCount=count end function '**************************************** '过滤重复记录 '**************************************** function killrepeatarr(tmparr) dim hi,I,J dim returnarr() redim returnarr(0) for J=0 to UBound(tmparr) hi=0 for I=0 to UBound(returnarr) if returnarr(I)=tmparr(J) then hi=1 next if hi=0 then redim preserve returnarr(I+1) returnarr(I+1)=tmparr(J) end if next sortarr=returnarr end function |
3:asp截取指定长度的字符串
'****************************** '截取指定长度的字符串 '****************************** Function InterceptStr(str,length) Dim str1,strLength,I,Counter '标志位 Dim flag flag=0 str1=Trim(str) strLength=Len(str) Counter=0 If length > 0 then If strLength >=1 then for I=1 to strLength If Asc(Mid(str,I,1))<0 or Asc(Mid(str,I,1))>255 then '是中文 flag=1 Counter=Counter+2 Else Counter=Counter+1 End If If Counter>=length then '剪切的字符长度未超过原字符 If flag=1 and Counter>length then '若是中文字符并且只剪切一个字节 str1=Left(str1,I-1) Else str1=Left(str1,I) End If Exit for End If Next InterceptStr=str1 Else InterceptStr="" End If Else InterceptStr="" End If End Function '*************************** 'FCK中获取图片 '*************************** Function getImages(Str) Set re =New RegExp re.Pattern = "<img(.+?)src=[""|\']*([^\s]+?)[""|\']*(\s|>)" '"<img(.+?)src=""*([^\s]+?)""*(\s|>)" re.Global =True re.IgnoreCase =True Set Cont = re.Execute(Str) For Each Match1 in Cont Images = Images + Match1.SubMatches(1)&"|" Next getImages = Mid(Images,1, Len(Images)-1) End Function |
4:asp检查组件是否已经安装
<%
'函数名:IsObjInstalled '作 用:检查组件是否已经安装 '参 数:strClassString ----组件名 '返回值:True ----已经安装 ' False ----没有安装 function IsObjInstalled(strClassString) on error resume next IsObjInstalled = False err = 0 dim xTestObj set xTestObj = Server.createobject(strClassString) if 0 = err then IsObjInstalled = True set xTestObj = nothing err = 0 end function %> |
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生成指定类型的随机字符串
'函数:RandomStr '作用:生成指定类型的随机字符串 '参数:IsIgnoreCase(大小写字母状态) ' IsStatus(数字、字母组合) ' CodeLen(字符串长度) Function RandomStr(ByVal IsIgnoreCase,ByVal IsStatus,ByVal CodeLen) Dim NumStr,CharStr,Str Dim RCodeItem,RCodeStart,RCodeStr NumStr="0123456789" CharStr="ABCDEFGHIJKLMNOPQRSTUVWXYZ" Select Case UCase(IsIgnoreCase) '选择字符串类型 Case "A":CharStr=CharStr&LCase(CharStr) Case "U":CharStr=CharStr Case "L":CharStr=LCase(CharStr) Case Else:CharStr=CharStr&LCase(CharStr) End Select Select Case UCase(IsStatus)'输出组合类型 Case "A":Str=NumStr&CharStr Case "N":Str=NumStr'Only Number Case "C":Str=CharStr'Only Char Case Else:Str=NumStr&CharStr End Select Randomize For RCodeItem=0 To CodeLen-1 RCodeStart=Int(Rnd*Len(Str)) RCodeStr=RCodeStr&Mid(Str,RCodeStart+1,1) Next RandomStr=RCodeStr End Function |
7:asp取得某个网页的内容
'取得某个网页的内容 function getHTTPPage(url) dim Http set Http=server.createobject("MSXML2.XMLHTTP") Http.open "GET",url,false Http.send if Http.readystate<>4 then exit function end if getHTTPPage=bytesToBSTR(Http.responseBody,"GB2312") set http=nothing if err.number<>0 then err.Clear end if end function Function BytesToBstr(body,Cset) dim objstream set objstream = Server.CreateObject("adodb.stream") objstream.Type = 1 objstream.Mode =3 objstream.Open objstream.Write body objstream.Position = 0 objstream.Type = 2 objstream.Charset = Cset BytesToBstr = objstream.ReadText objstream.Close set objstream = nothing End Function |
8:asp的验证码
'asp的验证码
Sub Com_CreateValidCode(pSN)
Response.Expires = -9999
Response.AddHeader "Pragma","no-cache"
Response.AddHeader "cache-ctrol","no-cache"
Response.ContentType = "Image/BMP"
Randomize
Dim i, ii, iii
Const cOdds = 8 '杂点出现的机率
Const cAmount = 10 '文字数量
Const cCode = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
'颜色的数据(字符,背景)
Dim vColorData(1)
vColorData(0) = ChrB(0) & ChrB(0) & ChrB(255) ' 蓝0,绿0,红0(黑色)
vColorData(1) = ChrB(235) & ChrB(235) & ChrB(235) ' 蓝250,绿236,红211(浅蓝色)
'随机产生字符
Dim vCode(4), vCodes
For i = 0 To 3
vCode(i) = Int(Rnd * cAmount)
vCodes = vCodes & Mid(cCode, vCode(i) + 1, 1)
Next
Session(pSN) = vCodes '记录入Session
' 字符的数据
Dim vNumberData(35)
vNumberData(0) = "1110000111110111101111011110111101001011110100101111010010111101001011110111101111011110111110000111"
vNumberData(1) = "1111011111110001111111110111111111011111111101111111110111111111011111111101111111110111111100000111"
vNumberData(2) = "1110000111110111101111011110111111111011111111011111111011111111011111111011111111011110111100000011"
vNumberData(3) = "1110000111110111101111011110111111110111111100111111111101111111111011110111101111011110111110000111"
vNumberData(4) = "1111101111111110111111110011111110101111110110111111011011111100000011111110111111111011111111000011"
vNumberData(5) = "1100000011110111111111011111111101000111110011101111111110111111111011110111101111011110111110000111"
vNumberData(6) = "1111000111111011101111011111111101111111110100011111001110111101111011110111101111011110111110000111"
vNumberData(7) = "1100000011110111011111011101111111101111111110111111110111111111011111111101111111110111111111011111"
vNumberData(8) = "1110000111110111101111011110111101111011111000011111101101111101111011110111101111011110111110000111"
vNumberData(9) = "1110001111110111011111011110111101111011110111001111100010111111111011111111101111011101111110001111"
vNumberData(10) = "1111011111111101111111101011111110101111111010111111101011111100000111110111011111011101111000100011"
vNumberData(11) = "1000000111110111101111011110111101110111110000111111011101111101111011110111101111011110111000000111"
vNumberData(12) = "1110000011110111101110111110111011111111101111111110111111111011111111101111101111011101111110001111"
vNumberData(13) = "1000001111110111011111011110111101111011110111101111011110111101111011110111101111011101111000001111"
vNumberData(14) = "1000000111110111101111011011111101101111110000111111011011111101101111110111111111011110111000000111"
vNumberData(15) = "1000000111110111101111011011111101101111110000111111011011111101101111110111111111011111111000111111"
vNumberData(16) = "1110000111110111011110111101111011111111101111111110111111111011100011101111011111011101111110001111"
vNumberData(17) = "1000100011110111011111011101111101110111110000011111011101111101110111110111011111011101111000100011"
vNumberData(18) = "1100000111111101111111110111111111011111111101111111110111111111011111111101111111110111111100000111"
vNumberData(19) = "1110000011111110111111111011111111101111111110111111111011111111101111111110111110111011111000011111"
vNumberData(20) = "1000100011110111011111011011111101011111110001111111010111111101101111110110111111011101111000100011"
vNumberData(21) = "1000111111110111111111011111111101111111110111111111011111111101111111110111111111011110111000000011"
vNumberData(22) = "1000100011110010011111001001111100100111110101011111010101111101010111110101011111010101111001010011"
vNumberData(23) = "1000100011110011011111001101111101010111110101011111010101111101100111110110011111011001111000110111"
vNumberData(24) = "1110001111110111011110111110111011111011101111101110111110111011111011101111101111011101111110001111"
vNumberData(25) = "1000000111110111101111011110111101111011110000011111011111111101111111110111111111011111111000111111"
vNumberData(26) = "1110001111110111011110111110111011111011101111101110111110111011111011101001101111011001111110001011"
vNumberData(27) = "1000001111110111011111011101111101110111110000111111010111111101101111110110111111011101111000110011"
vNumberData(28) = "1110000011110111101111011110111101111111111001111111111001111111111011110111101111011110111100000111"
vNumberData(29) = "1000000011101101101111110111111111011111111101111111110111111111011111111101111111110111111110001111"
vNumberData(30) = "1000100011110111011111011101111101110111110111011111011101111101110111110111011111011101111110001111"
vNumberData(31) = "1000100011110111011111011101111101110111111010111111101011111110101111111010111111110111111111011111"
vNumberData(32) = "1001010011110101011111010101111101010111110101011111001001111110101111111010111111101011111110101111"
vNumberData(33) = "1000100011110111011111101011111110101111111101111111110111111110101111111010111111011101111000100011"
vNumberData(34) = "1000100011110111011111011101111110101111111010111111110111111111011111111101111111110111111110001111"
vNumberData(35) = "1100000011110111011111111101111111101111111110111111110111111111011111111011111111101110111100000011"
' 输出图像文件头
Response.BinaryWrite ChrB(66) & ChrB(77) & ChrB(230) & ChrB(4) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & _
ChrB(0) & ChrB(0) & ChrB(54) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(40) & ChrB(0) & ChrB(0) & ChrB(0) & _
ChrB(40) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(10) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(1) & ChrB(0)
' 输出图像信息头
Response.BinaryWrite ChrB(24) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(176) & ChrB(4) & _
ChrB(0) & ChrB(0) & ChrB(18) & ChrB(11) & ChrB(0) & ChrB(0) & ChrB(18) & ChrB(11) & ChrB(0) & ChrB(0) & _
ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0)
For i = 9 To 0 Step -1 ' 历经所有行
For ii = 0 To 3 ' 历经所有字
For iii = 1 To 10 ' 历经所有像素
' 逐行、逐字、逐像素地输出图像数据
If Rnd * 99 + 1 < cOdds Then ' 随机生成杂点
Response.BinaryWrite vColorData(0)
Else
Response.BinaryWrite vColorData(Mid(vNumberData(vCode(ii)), i * 10 + iii, 1))
End If
Next
Next
Next
End Sub
dim sName
sName = request("s")
if sName = "" then
Call Com_CreateValidCode("VERIFYNUM")
else
Call Com_CreateValidCode(sName)
end if
上一篇:ASP常用代码段之八 下一篇:ASP常用代码段之十