推薦:Asp+Ajax實現無刷新增加好友由于工作關系,要做個人空間,其中有一功能是增加對方為好友.如圖: 用到的方法是ajax,費話少說貼切代碼: a href=javascript:void(0); onClick =add_username('%= rs(username) %');加為好友/a,用到的js驗證: script language = JavaScript src=ajax.
一個用來實現tag功能的asp類,具體的作用,如果您可以讀懂的話就可以明白了了。
修改記錄:
1,增加擴展函數,2006-12-3
<%
'******************************
'類名:tagEngine
'名稱:標簽引擎
'日期:2006-11-29
'作者:西樓冷月
'網址:www.xilou.net | www.chinaCMS.org
'描述:只有提取標簽功能,沒有解析標簽功能
'版權:轉載請注名出處,作者
'******************************
'最后修改:2006-12-3
'修改次數:3
'修改說明:修改正則,使匹配更精確
'目前版本:v1.1.3
'******************************
Class tagEngine
Private regEx'正則對象
'定義標簽規則
Private tagbegin
Private tagend
Private blockbegin_begin
Private blockbegin_end
Private blockend_begin
Private blockend_end
'//初始化
Private Sub Class_Initialize()
'初始化標簽規則
tagbegin="{"
tagend="}"
blockbegin_begin="<Block:"
blockbegin_end =">"
blockend_begin ="</Block:"
blockend_end =">"
'初始化正則對象
Set regEx=new RegExp
regEx.IgnoreCase=True'不區分大小寫
regEx.Global=True'全局匹配
End Sub
Private Sub Class_Terminate()
'釋放對象
If IsObject(regEx) Then Set regEx=Nothing
End Sub
'方法:resetPattern()
'參數:
'返回:無返回值
'作用:重設標簽規則
Public Sub resetPattern(tagbegin,tagend,_
blockbegin_begin,_
blockbegin_end,_
blockend_begin,_
blockend_end _
)
tagbegin=tagbegin
tagend=tagend
blockbegin_begin=blockbegin_begin
blockbegin_end =blockbegin_end
blockend_begin =blockend_begin
blockend_end =blockend_end
End Sub
'方法:getBlocks(temp,blockname)
'參數:temp,要匹配的內容;blockname,區塊標志名稱
'返回:返回集合對象(Matches)
'作用:獲取塊標簽集合
Public Function getBlocks(temp,blockname)
Dim pattern
pattern="("&blockbegin_begin&"[ ]*"&blockname&"/b[/w/W]*?"&blockbegin_end
pattern=pattern&")([/w/W]*?)"&blockend_begin&"[ /n/r]*"&blockname&"[ ]*"&blockend_end
'Response.Write pattern
regEx.Pattern=pattern
Set getBlocks=regEx.Execute(temp)'返回匹配集合
End Function
'方法:getBlockByAtt(temp,attributename,attributevalue)
'參數:temp,要匹配的內容;attributename,屬性名稱;attributevalue,屬性值
'返回:返回集合對象(Matches)
'作用:根據塊標簽里的某個屬性的值取得符合的塊集合
Public Function getBlockByAtt(temp,attributename,attributevalue)
Dim pattern
pattern="("&blockbegin_begin&"[/w/W]*?[ /n/r]+"&attributename
pattern=pattern&"[ ]*=[ ]*/"&Chr(34)&attributevalue&"/"&Chr(34)&"[ /n/r]*[/w/W]*?"
pattern=pattern&blockbegin_end
pattern=pattern&")([/w/W]*?)"&blockend_begin&"[/w/W]*?"&blockend_end
'Response.Write pattern
regEx.Pattern=pattern
Set getBlockByAtt=regEx.Execute(temp)'返回匹配集合
End Function
'方法:getAttValue(temp,attributename)
'參數:temp,要匹配的內容;attributename,屬性名稱
'返回:返回集合對象(Matches)
'作用:獲取塊標簽內的屬性值
Public Function getAttValue(temp,attributename)
Dim pattern
pattern="[ /n/r]+"&attributename&"[ ]*=[ ]*/"&Chr(34)&"([^/f/n/r/t/v/"&Chr(34)&"]*?)/"&Chr(34)
'Response.Write pattern
regEx.Pattern=pattern
Set getAttValue=regEx.Execute(temp)
End Function
'方法:parseTag(temp,tagname,tagvalue)
'參數:temp,要匹配的內容;attributename,屬性名稱;attributevalue,屬性值
'返回:返回替換后的字符串
'作用:替換簡單標簽
Public Function parseTag(temp,tagname,tagvalue)
Dim pattern
'pattern=tagbegin&"[ ]*"&tagname&"[ ]*"&tagend
pattern=tagbegin&tagname&tagend
regEx.pattern=pattern
parseTag=regEx.Replace(temp,tagvalue)
End Function
'方法:clearBlocks(temp)
'參數:temp,要匹配的內容
'返回:返回清除后的字符串
'作用:清除所有塊標簽
Public Function clearBlocks(temp)
Dim pattern
pattern=blockbegin_begin&"[/w/W]*?"&blockbegin_end&"[/w/W]*?"
pattern=pattern&blockend_begin&"[/w/W]*?"&blockend_end
regEx.pattern=pattern
clearBlocks=regEx.Replace(temp,"")
End Function
'方法:clearTags(temp)
'參數:temp,要匹配的內容
'返回:返回清除后的字符串
'作用:清除所有的單標簽
Public Function clearTags(temp)
Dim pattern
pattern=tagbegin&"[^/f/n/r/t/v]*?"&tagend
regEx.pattern=pattern
clearTags=regEx.Replace(temp,"")
End Function
'方法:showError(errdes)
'參數:errdes,錯誤描述
'返回:無
'作用:顯示錯誤
Public Sub showError(errdes)
Dim errinfo,cssstyle
cssstyle="style="&Chr(34)
cssstyle=cssstyle&"font:bold 12px 150%,'Arial';border:1px solid #CC3366;"
cssstyle=cssstyle&"width:50%;color:#990066;padding:2px;"&Chr(34)
errinfo=vbcrlf&"<ul "&cssstyle&"><li>"&errdes&"</li></ul>"&vbcrlf
Response.Write errinfo
End Sub
'******************標準功能結束****************
'以下是自定義擴展功能
'方法:EXT_getSimpleBlocks(temp,blockname)
'參數:temp,要匹配的內容;blockname,區塊標志名稱
'返回:返回集合對象(Matches)
'作用:獲取簡單塊標簽集合
'例子:<Block:new id="" loop=""/>
Public Function EXT_getSimpleBlocks(temp,blockname)
Dim pattern
Dim blockbegin,blockend
'重新定義標簽規則
blockbegin="<Block:"
blockend ="/>"
pattern=blockbegin&"[ ]*"&blockname&"/b[/w/W]*?"&blockend
regEx.pattern=pattern
Set EXT_getSimpleBlocks=regEx.Execute(temp)
End Function
'******************標準功能結束****************
'以下是自定義擴展功能
'方法:EXT_getSimpleBlocks(temp,blockname)
'參數:temp,要匹配的內容;blockname,區塊標志名稱
'返回:返回集合對象(Matches)
'作用:獲取簡單塊標簽集合
'例子:<Block:new id="" loop=""/>
Public Function EXT_getSimpleBlocks(temp,blockname)
Dim pattern
Dim blockbegin,blockend
'重新定義標簽規則
blockbegin="<Block:"
blockend ="/>"
pattern=blockbegin&"[ ]*"&blockname&"/b[/w/W]*?"&blockend
regEx.pattern=pattern
Set EXT_getSimpleBlocks=regEx.Execute(temp)
End Function
'方法:EXT_getTEXT(path)
'參數:path,要讀取的文本相對或絕對路徑
'返回:返回文本內容
'作用: 讀取文件
'例子:c=EXT_getTEXT("tpl.htm")
Public Function EXT_getTEXT(path)
Dim fso,f,text
On Error Resume Next
Set fso = CreateObject("Scripting.FileSystemObject")
Set f=Fso.OpenTextFile(path)
text=f.ReadAll
If Err Then
Err.Clear
showError "讀取文件出錯..."
If IsObject(fso) Then Set fso=Nothing
Exit Function
End If
If IsObject(fso) Then Set fso=Nothing
EXT_getTEXT=text
End Function
'方法:EXT_getIncludeFile(temp)
'參數:temp,要匹配的內容
'返回:返回集合對象(Matches)
'作用: 解析<!--#include file="tpl.html"-->的區塊
'例子:EXT_getIncludeFile(temp)(0).SubMatches(0),返回第一個匹配的文件名
Public Function EXT_getIncludeFile(temp)
Dim pattern
Dim blockbegin,blockend
'重新定義標簽規則
blockbegin="<!--#include"
blockend ="-->"
pattern=blockbegin&"[ ]*file[ ]*=[ ]*/""([/w/W]*?)/""[ ]*"&blockend
regEx.pattern=pattern
Set EXT_getIncludeFile=regEx.Execute(temp)
End Function
End Class
%>
分享:ASP限制ip投票完整實例代碼由于工作關系,要做個人空間,其中有一功能是對用戶投票,要求同一IP只能對同一用戶投票一次,貼Asp代碼: % '作者:無情 出處: db_conn(dbs) Voteusername=trim(request.QueryString(username)) rs_create(select username from [user] where username ='
新聞熱點
疑難解答