|
<STRONG><FONT size=2><FONT face=Arial><SPAN class=smalltxt twffan="done"><SPAN class=bold twffan="done">发段代码,网上发现的!精华ASP</SPAN></SPAN><BR><BR></FONT></FONT></STRONG><SPAN style="FONT-SIZE: 12px" twffan="done">1. oncontextmenu="window.event.returnvalue=false" 将彻底屏蔽鼠标右键<BR> <table border oncontextmenu=return(false)><td>no</table> 可用于Table<BR>2. <body onselectstart="return false"> 取消选取、防止复制<BR>3. onpaste="return false" 不准粘贴<BR>4. oncopy="return false;" oncut="return false;" 防止复制<BR>5. <link rel="Shortcut Icon" href="favicon.ico"> IE地址栏前换成自己的图标<BR>6. <link rel="Bookmark" href="favicon.ico"> 可以在收藏夹中显示出你的图标<BR>7. <input style="ime-mode:disabled"> 关闭输入法<BR>8. 永远都会带着框架<BR><script language="java script"><!--<BR> if (window == top)top.location.href = "frames.htm"; //frames.htm为框架网页<BR>// --></script><BR>9. 防止被人frame<BR><SCRIPT LANGUAGE=java script><!-- <BR> if (top.location != self.location)top.location=self.location;<BR>// --></SCRIPT><BR>10. <noscript><iframe src=*.html></iframe></noscript> 网页将不能被另存为<BR>11. <input type=button value=查看网页源代码 <BR>onclick="window.location = 'view-source:'+ 'http://www.csdn.net/';"><BR>12. 怎样通过asp的手段来检查来访者是否用了代理<BR><% if Request.ServerVariables("HTTP_X_FORWARDED_FOR")<>"" then<BR>response.write "<font color=#FF0000>您通过了代理服务器,"& _<BR>"真实的IP为"&Request.ServerVariables("HTTP_X_FORWARDED_FOR")<BR>end if<BR>%><BR>13. 取得控件的绝对位置<BR>//java script<BR><script language="java script"><BR>function getIE(e){<BR> var t=e.offsetTop;<BR> var l=e.offsetLeft;<BR> while(e=e.offsetParent){<BR> t+=e.offsetTop;<BR> l+=e.offsetLeft;<BR> }<BR> alert("top="+t+"\nleft="+l);<BR> }<BR></script><BR>//VBScript<BR><script language="VBScript"><!--<BR>function getIE()<BR> dim t,l,a,b<BR> set a=document.all.img1<BR> t=document.all.img1.offsetTop<BR> l=document.all.img1.offsetLeft<BR> while a.tagName<>"BODY"<BR> set a = a.offsetParent<BR> t=t+a.offsetTop<BR> l=l+a.offsetLeft<BR> wend<BR> msgbox "top="&t&chr(13)&"left="&l,64,"得到控件的位置"<BR>end function<BR>--></script><BR>14. 光标是停在文本框文字的最后<BR><script language="java script"><BR>function cc()<BR>{<BR> var e = event.srcElement;<BR> var r =e.createTextRange();<BR> r.moveStart('character',e.value.length);<BR> r.collapse(true);<BR> r.select();<BR>}<BR></script><BR><input type=text name=text1 value="123" onfocus="cc()"><BR>15. 判断上一页的来源<BR>asp:<BR>request.servervariables("HTTP_REFERER")<BR>java script:<BR>document.referrer<BR>16. 最小化、最大化、关闭窗口<BR><object id=hh1 classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11"> <BR><param name="Command" value="Minimize"></object><BR><object id=hh2 classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11"> <BR><param name="Command" value="Maximize"></object><BR><OBJECT id=hh3 classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11"><BR><ARAM NAME="Command" value="Close"></OBJECT><BR><input type=button value=最小化 onclick=hh1.Click()><BR><input type=button value=最大化 onclick=hh2.Click()><BR><input type=button value=关闭 onclick=hh3.Click()><BR>本例适用于IE<BR>17. <BR><%<BR>'定义数据库连接的一些常量<BR>Const adOpenForwardOnly = 0 '游标只向前浏览记录,不支持分页、Recordset、BookMark<BR>Const adOpenKeyset = 1 '键集游标,其他用户对记录说做的修改将反映到记录集中,但其他用户增加或删除记录不会反映到记录集中。支持分页、Recordset、BookMark<BR>Const adOpenDynamic = 2 '动态游标功能最强,但耗资源也最多。用户对记录说做的修改,增加或删除记录都将反映到记录集中。支持全功能浏览(ACCESS不支持)。<BR>Const adOpenStatic = 3 '静态游标,只是数据的一个快照,用户对记录说做的修改,增加或删除记录都不会反映到记录集中。支持向前或向后移动<BR>Const adLockReadOnly = 1 '锁定类型,默认的,只读,不能作任何修改<BR>Const adLockPessimistic = 2 '当编辑时立即锁定记录,最安全的方式<BR>Const adLockOptimistic = 3 '只有在调用Update方法时才锁定记录集,而在此前的其他操作仍可对当前记录进行更改、插入和删除等<BR>Const adLockBatchOptimistic = 4 '当编辑时记录不会被锁定,而更改、插入和删除是在批处理方式下完成的<BR>Const adCmdText = &H0001<BR>Const adCmdTable = &H0002<BR>%><BR>18. 网页不会被缓存<BR>HTM网页<BR><META HTTP-EQUIV="pragma" CONTENT="no-cache"><BR><META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate"><BR><META HTTP-EQUIV="expires" CONTENT="Wed, 26 Feb 1997 08:21:57 GMT"><BR>或者<META HTTP-EQUIV="expires" CONTENT="0"><BR>ASP网页<BR> Response.Expires = -1<BR> Response.ExpiresAbsolute = Now() - 1<BR> Response.cachecontrol = "no-cache"<BR>HP网页<BR>header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");<BR>header("Cache-Control: no-cache, must-revalidate");<BR>header("ragma: no-cache");<BR><BR>19. 检查一段字符串是否全由数字组成<BR><script language="java script"><!--<BR>function checkNum(str){return str.match(/\D/)==null}<BR>alert(checkNum("1232142141"))<BR>alert(checkNum("123214214a1"))<BR>// --></script><BR>20. 获得一个窗口的大小<BR>document.body.clientWidth,document.body.clientHeight<BR>21. 怎么判断是否是字符<BR>if (/[^\x00-\xff]/g.test(s)) alert("含有汉字");<BR>else alert("全是字符");<BR>22.TEXTAREA自适应文字行数的多少<BR><textarea rows=1 name=s1 cols=27 onpropertychange="this.style.posHeight=this.scrollHeight"><BR></textarea><BR>23. 日期减去天数等于第二个日期<BR><script language=java script><BR>function cc(dd,dadd)<BR>{<BR>//可以加上错误处理<BR>var a = new Date(dd)<BR>a = a.valueOf()<BR>a = a - dadd * 24 * 60 * 60 * 1000<BR>a = new Date(a)<BR>alert(a.getFullYear() + "年" + (a.getMonth() + 1) + "月" + a.getDate() + "日")<BR>}<BR>cc("12/23/2002",2)<BR></script><BR>24. 选择了哪一个Radio<BR><HTML><script language="vbscript"><BR>function checkme()<BR> for each ob in radio1<BR> if ob.checked then window.alert ob.value<BR> next<BR>end function<BR></script><BODY><BR><INPUT name="radio1" type="radio" value="style" checked>Style<BR><INPUT name="radio1" type="radio" value="barcode">Barcode<BR><INPUT type="button" value="check" onclick="checkme()"><BR></BODY></HTML><BR>25.获得本页url的request.servervariables("")集合<BR>Response.Write "<TABLE border=1><!-- Table Header --><TR><TD><B>Variables</B></TD><TD><B>value</B></TD></TR>"<BR>for each ob in Request.ServerVariables<BR>Response.Write "<TR><TD>"&ob&"</TD><TD>"&Request.ServerVariables(ob)&"</TD></TR>"<BR>next<BR>Response.Write "</TABLE>"<BR>26.<BR>本机ip<%=request.servervariables("remote_addr")%><BR>服务器名<%=Request.ServerVariables("SERVER_NAME")%><BR>服务器IP<%=Request.ServerVariables("LOCAL_ADDR")%><BR>服务器端口<%=Request.ServerVariables("SERVER_PORT")%><BR>服务器时间<%=now%><BR>IIS版本<%=Request.ServerVariables"SERVER_SOFTWARE")%><BR>脚本超时时间<%=Server.ScriptTimeout%><BR>本文件路径<%=server.mappath(Request.ServerVariables("SCRIPT_NAME"))%><BR>服务器CPU数量<%=Request.ServerVariables("NUMBER_OF_PROCESSORS")%><BR>服务器解译引擎<%=ScriptEngine & "/"& ScriptEngineMajorVersion &"."&ScriptEngineMinorVersion&"."& ScriptEngineBuildVersion %><BR>服务器操作系统<%=Request.ServerVariables("OS")%><BR>27.ENTER键可以让光标移到下一个输入框<BR><input onkeydown="if(event.keyCode==13)event.keyCode=9"><BR>28. 检测某个网站的链接速度:<BR>把如下代码加入<body>区域中:<BR><script language=java script><BR>tim=1<BR>setInterval("tim++",100)<BR>b=1<BR>var autourl=new Array()<BR>autourl[1]="www.njcatv.net"<BR>autourl[2]="javacool.3322.net"<BR>autourl[3]="www.sina.com.cn"<BR>autourl[4]="www.nuaa.edu.cn"<BR>autourl[5]="www.cctv.com"<BR>function butt(){<BR>document.write("<form name=autof>")<BR>for(var i=1;i<autourl.length;i++)<BR>document.write("<input type=text name=txt"+i+" size=10 value=测试中……> =》<input type=text name=url"+i+" size=40> =》<input type=button value=GO onclick=window.open(this.form.url"+i+".value)><br/>")<BR>document.write("<input type=submit value=刷新></form>")<BR>}<BR>butt()<BR>function auto(url){<BR>document.forms[0]["url"+b].value=url<BR>if(tim>200)<BR>{document.forms[0]["txt"+b].value="链接超时"}<BR>else<BR>{document.forms[0]["txt"+b].value="时间"+tim/10+"秒"}<BR>b++<BR>}<BR>function run(){for(var i=1;i<autourl.length;i++)document.write("<img src=http://"+autourl+"/"+Math.random()+" width=1 height=1 onerror=auto('http://";+autourl+"')>")}<BR>run()</script><BR><BR>29. 各种样式的光标<BR>auto :标准光标<BR>default :标准箭头<BR>hand :手形光标<BR>wait :等待光标<BR>text :I形光标<BR>vertical-text :水平I形光标<BR>no-drop :不可拖动光标<BR>not-allowed :无效光标<BR>help :?帮助光标<BR>all-scroll :三角方向标<BR>move :移动标<BR>crosshair :十字标<BR>e-resize<BR>n-resize<BR>nw-resize<BR>w-resize<BR>s-resize<BR>se-resize<BR>sw-resize<BR>1.本地无缓存,每次自动刷新<BR>response.expires=0<BR>response.addHeader "pragma" , "no-cache"<BR>response.addHeader "cache-control" , "private"<BR>2.修改contentType并下载gif等格式<BR><%<BR>function dl(f,n)<BR>on error resume next<BR><BR>set s=CreateObject("Adodb.Stream") <BR>S.Mode=3 <BR>S.Type=1 <BR>S.Open <BR>s.LoadFromFile(server.mappath(f))<BR>if err.number>0 then <BR> response.write err.number & ":" & err.description<BR>else<BR> response.contentType="application/x-gzip"<BR> response.addheader "Content-Disposition:","attachment; filename=" & n<BR> response.binarywrite(s.Read(s.size))<BR>end if<BR>end function<BR>call dl("012922501.gif","t1.gif")<BR>%><BR><BR>19. 检查一段字符串是否全由数字组成<BR><script language="java script"><!--<BR>function checkNum(str){return !/\D/.test(str)}<BR>alert(checkNum("1232142141"))<BR>alert(checkNum("123214214a1"))<BR>// --></script><BR>20. 获得一个窗口的大小<BR>document.body.clientWidth,document.body.clientHeight<BR>document.body.offsetWidth,document.body.offsetHeight<BR>有时还需要知道window.screenTop,window.screenLeft<BR>21. 怎么判断是否含有汉字<BR>if (escape(str).indexOf("%u")!=-1) alert("含有汉字");<BR>else alert("全是字符");<BR>22.TEXTAREA自适应文字行数的多少<BR>IE 5.5+ 可以用 overflow-y:visible<BR><textarea rows=1 name=s1 cols=27 style="overflow-y:visible"><BR></textarea><BR>23. 日期减去天数等于第二个日期<BR><script language=java script><BR>function cc(dd,dadd)<BR>{<BR>//可以加上错误处理<BR>var d = new Date(dd.replace("-","/"))<BR>d.setDate(d.getDate()+dadd)<BR>alert(d.getFullYear() + "年" + (d.getMonth() + 1) + "月" + d.getDate() + "日")<BR>}<BR>cc("2002-2-28",2)<BR></script></SPAN> <BR><BR> |
|