免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1393 | 回复: 0
打印 上一主题 下一主题

从网上“偷”了一些有点用的代码 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-12-03 20:42 |只看该作者 |倒序浏览

一。防止ACCESS数据库被下载
二。让IFRAME自动适应高度
三。提交时自动复制内容到剪贴板
四。一个生成HTML的类
五。超级漂浮的代码
六。asp文件生成js文件
七。input高级限制级用法及下拉框选项分组
八。大臉娃娃符號表
九。转一个注册时阅读条款时间控制
十。一个格式化时间日期函数">
十一。又一个格式化时间日期函数
十二。ASP连接数据库的6种方法
十三。JS倒计时代码
十四。仿动易2006限制IP功能代码

====以下部分为代码================================================================

一。防止ACCESS数据库被下载
执行完毕后将数据库改成 .asp 后缀文件
程序代码

二。让IFRAME自动适应高度
function autoResize() {
try {
document.all["main"].style.height=main.document.body.scrollHeight
}
catch(e){}
}


三。提交时自动复制内容到剪贴板
程序代码
提交时自动复制到剪贴板
/*功能:提交时自动复制到剪贴板 */
function copyText(obj) {
ie = (document.all)? true:false
if (ie){
var rng = document.body.createTextRange();
rng.moveToElementText(obj);
rng.scrollIntoView();
rng.select();
rng.execCommand("Copy");
rng.collapse(false);
}
}
function autocopy() {
if (this.document.formname.isautocopy.checked) {
copyText(this.document.formname.icontent);
}
}
提交时复制内容到剪贴板
四。一个生成HTML的类
不知道是谁写的,不过倒是个好东西
Htmlmaker.asp 类文件
Private Sub class_initialize()
HtmlFolder=Datename1(now)
HtmlFilename=Datename2(now)&".html"
HtmlContent=""
End Sub
Private Sub class_terminate()
End Sub
'/*************************
'/ Html文件生成
'/*************************
Public Sub Htmlmake()
On Error Resume Next
dim filepath,fso,fout
filepath = HtmlFolder&"/"&HtmlFilename
Set fso = Server.CreateObject("Scripting.FileSystemObject")
If fso.FolderExists(HtmlFolder) Then
Else
fso.CreateFolder(Server.MapPath(HtmlFolder))
End If
Set fout = fso.CreateTextFile(Server.MapPath(filepath),true)
fout.WriteLine HtmlContent
fout.close
End Sub
'/*************************
'/ Html文件删除
'/*************************
Public Sub Htmldel()
dim filepath,fso
filepath = HtmlFolder&"/"&HtmlFilename
Set fso = CreateObject("Scripting.FileSystemObject")
fso.DeleteFile(Server.mappath(filepath))
Set fso = nothing
End Sub
End class
%>
test.asp
测试测试测试测试"
myhtml.Htmlmake
set myhtml=nothing
Response.Write("生成成功!!")
%>

五。超级漂浮的代码
超级漂浮的代码(漂的够猛)

var imagepath="/Learning/UploadFiles_9072/200608/20060831225502598.gif" //这里写图片的URL
var imagewidth=100  //这两行写图片的大小
var imageheight=100
var speed=3;
var imageclick="
http://www.158188.com/
" //这里写点击到的广告地址
var hideafter=0
var isie=0;
if(window.navigator.appName=="Microsoft Internet Explorer"&&window.navigator.appVersion.substring(window.navigator.appVersion.indexOf("MSIE")+5,window.navigator.appVersion.indexOf("MSIE")+8)>=5.5) {
isie=1;
}
else {
isie=0;
}
if(isie){
var preloadit=new Image()
preloadit.src=imagepath
}
function pop() {
if(isie) {
x=x+dx;y=y+dy;
oPopup.show(x, y, imagewidth, imageheight);
if(x+imagewidth+5>screen.width) dx=-dx;
if(y+imageheight+5>screen.height) dy=-dy;
if(x';
oPopup.document.body.onmouseover=new Function("clearTimeout(startani)")
oPopup.document.body.onmouseout=pop
oPopup.document.body.onclick=dowhat
pop();
if (hideafter>0)
setTimeout("dismisspopup()",hideafter*1000)
}

六。asp文件生成js文件
  
Creatjs.asp代码

" &title&" "&AddNewsDate&"
"
rs.movenext
loop
'生成JS文件
goaler = "" + goaler + ""
goaler = "document.write('" & goaler & "')"
FolderPath = Server.MapPath("./jsfile")
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set fout = fso.CreateTextFile(FolderPath&"\top.js")
fout.WriteLine goaler
'关闭连接
fout.close
set fout = nothing
rs.close
set rs = nothing
conn.close
set conn=nothing
%>
然后在你需要的页面写入这句代码:
在后台页面你可以点击按钮进行生成js代码:
生成最新新闻10条js文件:生成js文件

七。input高级限制级用法及下拉框选项分组
1.取消按钮按下时的虚线框
  在input里添加属性值 hideFocus 或者 HideFocus=true
2.只读文本框内容
在input里添加属性值 readonly
3.防止退后清空的TEXT文档(可把style内容做做为类引用)
  
4.ENTER键可以让光标移到下一个输入框
  
5.只能为中文(有闪动)
  
6.只能为数字(有闪动)
  
7.只能为数字(无闪动)
  57)) event.returnValue=false">
8.只能输入英文和数字(有闪动)
  
9.屏蔽输入法
  
10. 只能输入 数字,小数点,减号(-) 字符(无闪动)
  57)) event.returnValue=false">
11. 只能输入两位小数,三位小数(有闪动)
  57) && event.keyCode!=46 && event.keyCode!=45 || value.match(/^\d{3}$/) || /\.\d{3}$/.test(value)) {event.returnValue=false}" id=text_kfxe name=text_kfxe>
======================================================
下拉框选项分组

请选择一个
控制面板
私人信息
订阅
看谁在线
搜索论坛
论坛首页
--------------------
======================================================
取得数组最大值:
snum="345,231,56,786,1100,356,1200,300,685,111,134,765"
function GetMax(str)
num=split(str,",")
max=num(0)
for ii=0 to ubound(num)
if cint(num(ii))>cint(max) then max=num(ii)
response.Write "num="&num(ii)&",max="&max&"
"
next
GetMax=max
end function
response.Write "数组"&snum&"
最大值:"&GetMax(snum)
八。大臉娃娃符號表  
01.  02.
05. ╮( ̄▽ ̄)╭ 06. ╰( ̄▽ ̄)╭ 07. ╮( ̄﹏ ̄)╭ 08. ( ̄▽ ̄@)
09. ○( ̄﹏ ̄)○ 10.
13. /( ̄▽ ̄)♂ 14. /( ̄▽ ̄)♀ 15. ╭( ̄m ̄*)╮ 16. ╰( ̄▽ ̄)╯
17.  18. 帥( ̄▽ ̄)σ" 19. 羞(# ̄▽ ̄#) 20. ( ̄Q ̄)╯
21. 漲( ̄︶ ̄)↗ 22. 跌(┬_┬)↘ 23.
25. ╮(╯▽╰)╭ 26. ╮(╯_╰)╭ 27. ╮(﹀_﹀")╭ 28. ╰(‵□′)╯
29. (#-.-)/ 30. (︶︿︶)=凸 31. (((‵□′))怒 32. ╭(─╴─)╮
33. ˋ(′~‵")ˊ 34. ˋ(′o‵")ˊ 35. ˋ(′ε‵")ˊ 36. \(╯▼╰)/
37. ┐(─__─)┌ 38. 氣! 39. ┌(‵▽′)╭ 40. #(┬_┬)泣!
41.   42.
43. 看拳o(╬ ̄皿 ̄)=○# ( ̄#)3 ̄) 44. K.O
45. (╯‵□′)╯︵ ┴─┴ 翻桌啦! 46. 翻桌啦! ┴─┴ ︵ ╰(‵□′╰)
47. ╭∩╮( ̄▽ ̄)╭∩╮你有沒有搞錯! 48. 哼.哼.哼
49. \("▔□▔)/\("▔□▔)/\("▔□▔)/ 50. ~( ̄▽ ̄)~( ̄▽ ̄)~爽到不行~
51. ~( ̄3 ̄)~(︺ε﹀)~( ̄3 ̄)~快送醫! 52. 無影腳_
53. 笨蛋
55. ╭ (′▽`)╭(′▽`)╭(′▽`)╯Go! 56. ︿( ̄︶ ̄)︽( ̄︶ ̄)︿飛.飛.飛.
57. 兇手!兇手就是你!
59. 來嘛!╮(╯◇╰)╭口禾火~口禾火~ 60. …(⊙_⊙;)… ○圭~○列~怎麼醬?
61.
63. 有火星人~ \("▔□▔)/\("▔□▔)/ 64. 不要以為我不知道咩!┌(‵▽′)╭
65.
67. 我是優質大帥哥一枚. \( ̄▽ ̄)♂ 68. ♀( ̄▽ ̄)/ 我是優質大美女一枚.
69. ┐(─__─)┌ 你說我有啥米辦法咧~ 70. 吃飽飽,睡好好! ○(* ̄︶ ̄*)○
71. 有沒有被豬揍過啊? ○(#‵︿′#)○ 72. ε(┬┬_┬┬)3 我 真 命 苦 ..
73. 拆屋 ┴┴ ︵╰(‵□′)╯︵ ┴┴ 74. 冷到不行 ≡ ̄﹏ ̄≡ 冷到不行..
75.  我看你還是回火星去好了! 76.
77.
79. 無影腳昇級版 _
80. 惡魔集團o(‵▽′)ψ 81. ψ(╰_╯)σ‧‧☆咒 82. ψ( ̄︶ ̄)ψ( ̄︶ ̄)ψ
83. 嘟著嘴 ( ̄)︿( ̄) 84.(⊙o⊙) 目瞪口呆 85. \(~__~)/ 要抱抱啦...
86. (>﹏<) 不~要~啦 87. (⊙.⊙)a...怎樣? 88. 〒▽〒 哇哇~人家不依
89. o(一︿一+)o 怨.念 90. (─.─|||| 很多條線 91. (#--)/ 下次小心.
92. 鬼魂團 ㄟ(川.一ㄟ) 93. √(─皿─)√ 讓我咬 94. (′ 3`)y==~ 人生海海..
95. ( ̄y▽ ̄)╭ 唉唷唷~ 96. \(╯-╰)/ 不是我殺的 97. ( ̄▽ ̄#) = ﹏﹏ 飄走
98. m(_ _)m 大人饒命啊! 99. ╭(′▽`)╭(′▽`)╯(讓咱們一起奔向夕陽吧...)

九。转一个注册时阅读条款时间控制
欢迎注册E天娱乐:
条款若干........
(10)" name="agreeb">
(" + printnr +")";
}
}
//-->

十。一个格式化时间日期函数
我们有时候遇到的日期格式可能是2004-1-12 ,系统自动将月份中的0去掉了,但是有时候我们需要完整的日期格式 ,如:2004-01-12 那么怎么办呢?下面的几个函数可以轻松搞定。
'将一个一位的数字前面加零
function FillZero(str)
ttt=str
if len(str)=1 then
ttt="0" & str
end if
FillZero=ttt
end function
'转化日期,将 一位补上零 2003-1-2 --> 2003-01-02
function ConvertDate(tDate)
ttt=tDate
if isdate(tDate) then
ttt=year(tDate) & "-" & FillZero(month(tDate)) & "-" & FillZero(day(tDate))
end if
ConvertDate=ttt
end function
'输入一个日期时间串,转换成年四位,其他两位的新的日期时间串
function ConvertDateTime(tDateTime)
ttt=tDateTime
if isdate(tDateTime) then
ttt=year(tDateTime) & "-" & FillZero(month(tDateTime)) & "-" & FillZero(day(tDateTime)) & " " & FillZero(cstr(hour(tDateTime))) & ":" & FillZero(cstr(minute(tDateTime))) & ":" & FillZero(cstr(second(tDateTime)))
end if
ConvertDateTime=ttt
end function
十一。又一个格式化时间日期函数
函数名称:FormatDate
作用:将获得的时间格式化成你想要的样式显示出来,并且如果日期时间某个数值是1位数,则在其前面添加0
    如:获得的时间格式是 2006-6-25 14:6:41,在单位数字前加0将其变更成两位 2006-06-25 14:06:41
函数所含参数:DateAndTime, para
    DateAndTime:获得具体时间参数如 Now
    para:格式化后的时间样式,目前有10种样式可自行修改
    样式效果(Y 表示年,M 表示月,D 表示日,H 表示小时,MI 表示分钟,S 表示秒):
        1. Y-M-D H:MI:S
        2. Y-M-D
        3. Y/M/D
        4. Y年M月D日
        5. M-D
        6. M/D
        7. M月D日
        8. Y年M月
        9. Y-M
        10. Y/M
Function FormatDate(DateAndTime, para)
  On Error Resume Next
  Dim y, m, d, h, mi, s, strDateTime
  FormatDate = DateAndTime
  If Not IsNumeric(para) Then Exit Function
  If Not IsDate(DateAndTime) Then Exit Function
  y = Mid(CStr(Year(DateAndTime)),3)
  m = CStr(Month(DateAndTime))
  If Len(m) = 1 Then m = "0" & m
  d = CStr(Day(DateAndTime))
  If Len(d) = 1 Then d = "0" & d
  h = CStr(Hour(DateAndTime))
  If Len(h) = 1 Then h = "0" & h
  mi = CStr(Minute(DateAndTime))
  If Len(mi) = 1 Then mi = "0" & mi
  s = CStr(Second(DateAndTime))
  If Len(s) = 1 Then s = "0" & s
  Select Case para
  Case "1"
   strDateTime = y & "-" & m & "-" & d & " " & h & ":" & mi & ":" & s
  Case "2"
   strDateTime = y & "-" & m & "-" & d
  Case "3"
   strDateTime = y & "/" & m & "/" & d
  Case "4"
   strDateTime = y & "年" & m & "月" & d & "日"
  Case "5"
   strDateTime = m & "-" & d
  Case "6"
   strDateTime = m & "/" & d
  Case "7"
   strDateTime = m & "月" & d & "日"
  Case "8"
   strDateTime = y & "年" & m & "月"
  Case "9"
   strDateTime = y & "-" & m
  Case "10"
   strDateTime = y & "/" & m
  Case Else
   strDateTime = DateAndTime
  End Select
  FormatDate = strDateTime
End Function
十二。ASP连接数据库的6种方法
第一种 - 这种方法用在ACCESS中最多
strconn = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" _
& Server.MapPath("aspfree.mdb")
set conn = server.createobject("adodb.connection")
conn.open strconn
第二种-这种方法用在SQL SERVER中多
strconn = "Driver={SQL Server};Description=sqldemo;SERVER=127.0.0.1;" _
&"UID=LoginID;Password=;DATABASE=Database_Name"
set conn = server.createobject("adodb.connection")
conn.open strconn
第三种
strconn="Driver={Microsoft Access Driver(*.mdb)};" _
&"DBQ=F:\\Inetpub\\wwwroot\\somedir\\db1.mdb;DefaultDir=" _
&"f:\\Inetpub\\wwwroot\\somedir;uid=LoginID;" _
&"pwd=Password;DriverId=25;FIL=MSAccess;"
set conn = server.createobject("adodb.connection")
conn.open strconn
第四种运用系统数据源
The following uses a Data Source Name: Example
set conn = server.createobject("adodb.connection")
conn.open "Example"
第五种运用ODBC数据源,前提是你必须在控制面板的ODBC中设置数据源
set rs = server.createobject("adodb.recordset")
rs.open "tblname", "DSNName", 3, 3  第一种 - 这种方法用在ACCESS中最多
strconn = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" _
& Server.MapPath("aspfree.mdb")
set conn = server.createobject("adodb.connection")
conn.open strconn
第六种ASP连接Oracle
ConnString = "Provider=OraOLEDB.Oracle;PLSQLRSet=1;Password=gqshad;User ID=gqshad;Data Source=mip"
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open ConnString
十三。JS倒计时代码  

1)    document.write("离"+s+"还有"+dni +"天")
else if (dni == 1)      document.write("只有2天啦!")
else if (dni == 0)      document.write("只有1天啦!")
else     document.write(s+"好象已经过了哦!");  
-->


十四。仿动易2006限制IP功能代码
在数据库中新建一个字段用来存放IP,字段格式为备注
IP在该字段中格式如:1033218851----1033218865$$$1033218816----1033218848|||1033218851----1033218865$$$1033218816----1033218848
$$$表示IP在文本框内换行的回车符,也就是每个IP段用回车分隔,然后替换成$$$
|||表示黑白名单分隔符
1033218851----1033218865表示一个IP段
添加多个限定IP段,请用回车分隔。
限制IP段的书写方式,中间请用英文四个小横杠连接
如:255.255.255.0----255.255.255.255
///////////////////////////////////////////////////////////////////////////////////
在conn.asp中插入以下代码,并 Call IsIpLock 来判断和限制IP访问,此部分尚未调试
///////////////////////////////////////////////////////////////////////////////////
" & vbCrLf
        Response.Write "" & vbCrLf
        Response.Write "" & vbCrLf
        Response.Write "" & vbCrLf
        Response.Write "" & vbCrLf
        Response.Write "" & vbCrLf
        Response.write "
对不起!您的IP(" & /*取得用户真实IP*/ & ")被系统限制。" & vbCrLf
        Response.Write "" & vbCrLf
        Response.Write ""
        Response.End
    End If
End Sub
Function ChecKIPlock(ByVal sLockType, ByVal sLockList, ByVal sUserIP)
    Dim IpLock,rsLockIP,i
    Dim arrLockIPW, arrLockIPB, arrLockIPWCut, arrLockIPBCut
    IpLock = False
    ChecKIPlock = IpLock
    If sLockType = "" or IsNull(sLockType) Then Exit Function
    If sLockList = "" or IsNull(sLockList) Then Exit Function
    If sUserIP = "" or IsNull(sUserIP) Then Exit Function
    sUserIP = Etosky.EncodeIP(sUserIP)
    rsLockIP = Split(sLockList, "|||")
    If sLockType = 1 Then
        arrLockIPW = Split(Trim(rsLockIP(0)), "$$$")
        For i = 0 To UBound(arrLockIPW)
            If arrLockIPW(i)  "" Then
                arrLockIPWCut = Split(Trim(arrLockIPW(i)), "----")
                IpLock = True
                If arrLockIPWCut(0)  "" Then
                arrLockIPBCut = Split(Trim(arrLockIPB(i)), "----")
                IpLock = True
                If arrLockIPBCut(0) > sUserIP And sUserIP > arrLockIPBCut(1) Then IpLock = False
                If IpLock Then Exit For
            End If
        Next
    End If
    ChecKIPLock = IpLock
End Function
%>
///////////////////////////////////////////////////////////////////////////////////
在适当位置插入以下代码,用来简单加密、解密IP地址
///////////////////////////////////////////////////////////////////////////////////
'解密IP
Public Function DecodeIp(Sip)
    Dim strIp,sIp1,sIp2,sIp3,sIp4
    strIp = Sip
    If Not IsNumeric(strIp) Then
        DecodeIP = 0
        Exit Function
    End If
    sIp1 = Int(strIp / 256 / 256 / 256)
    sIp2 = Int((strIp - sIp1 * 256 * 256 * 256) / 256 / 256)
    sIp3 = Int((strIp - sIp1 * 256 * 256 * 256 - sIp2 *256 * 256) / 256)
    sIp4 = Int((strIp - sIp1 * 256 * 256 * 256 - sIp2 *256 * 256 - sIp3 * 256) + 1)
    Sip = sIp1 & "." & sIp2 & "." & sIp3 & "." & sIp4
    DecodeIp = Sip
End Function
%>
///////////////////////////////////////////////////////////////////////////////////
格式化显示IP地址,用后后台编辑限制的IP段
///////////////////////////////////////////////////////////////////////////////////
'这个用来表示读出数据库中的限制IP的字段内容
LockIp = "1033218851----1033218865$$$1033218816----1033218848|||1033218851----1033218865$$$1033218816----1033218848"
LockIp = Split(LockIP,"|||"
%>
白名单
黑名单
///////////////////////////////////////////////////////////////////////////////////
IP段提交保存部分
///////////////////////////////////////////////////////////////////////////////////
Function ChkIP(Ip,Num)   '用正则判断IP和IP段格式是否正确
    Dim RegEx
    Set RegEx = New RegExp
    If Num = 1 Then
        RegEx.Pattern = "^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}$"
    Else
        RegEx.Pattern = "^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}----\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}$"
    End If
    ChkIP = RegEx.Test(Ip)
End Function
Dim WhiteIP,arrLockIPW,arrLockIPWCut,arrLockIpWhite,LockIpWhite
Dim BlackIP,arrLockIPB,arrLockIPBCut,arrLockIpBlack,LockIpBlack
'IP白名单保存
WhiteIP = Trim(Request.Form("LockIpWhite"))
WhiteIP = Replace(WhiteIP,Chr(10),"")
arrLockIPW = Split(WhiteIP,Chr(13))
For i = 0 To Ubound(arrLockIPW)
    If Instr(arrLockIPW(i),"----") = 0 Then
        Response.Write "
请正确填写黑白名单IP地址。"
        Exit For
    End If
    arrLockIPWCut = Split(arrLockIPW(i),"----")
    If Not ChkIP(arrLockIPWCut(0),1) or Not ChkIP(arrLockIPWCut(1),1) or Not ChkIp(arrLockIPWCut(0) & "----" & arrLockIPWCut(1),0) Then
        Response.Write "
请正确填写黑白名单IP地址。"
        Exit For
    End If
    arrLockIpWhite = EncodeIP(arrLockIPWCut(0)) & "----" & EncodeIP(arrLockIPWCut(1))
    LockIpWhite = LockIpWhite & arrLockIpWhite & "$$$"
Next
LockIpWhite = RightCut(LockIpWhite,"$$$",3)
'IP黑名单保存
BlackIP = Trim(Request.Form("LockIpBlack"))
BlackIP = Replace(BlackIP,Chr(10),"")
arrLockIPB = Split(BlackIP,Chr(13))
For i = 0 To Ubound(arrLockIPB)
    If Instr(arrLockIPB(i),"----") = 0 Then
        Response.Write "
请正确填写黑白名单IP地址。"
        Exit For
    End If
    arrLockIPBCut = Split(arrLockIPB(i),"----")
    If Not ChkIP(arrLockIPBCut(0),1) or Not ChkIP(arrLockIPBCut(1),1) or Not ChkIp(arrLockIPBCut(0) & "----" & arrLockIPBCut(1),0) Then
        Response.Write "
请正确填写黑白名单IP地址。"
        Exit For
    End If
    arrLockIpBlack = EncodeIP(arrLockIPBCut(0)) & "----" & EncodeIP(arrLockIPBCut(1))
    LockIpBlack = LockIpBlack & arrLockIpBlack & "$$$"
Next
LockIpBlack = RightCut(LockIpBlack,"$$$",3)
'保存进数据库的IP段
LockIp = LockIpWhite & "|||" & LockIpBlack
Conn.Execute("Update [TableName] Set LockIp = '" & LockIp & "'")

====代码完,收工============================================================

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/6138/showart_209515.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP