ASP常用特效代码大全

合集下载

ASP编程常用代码精选集合(十二)

ASP编程常用代码精选集合(十二)

1:asp检查组件是否已经安装<% '函数名:IsObjInstalled'作用:检查组件是否已经安装'参数:strClassString ----组件名'返回值:True ----已经安装' False ----没有安装function IsObjInstalled(strClassString)on error resume nextIsObjInstalled = Falseerr = 0dim xTestObjset xTestObj = Server.createobject(strClassString)if0= err then IsObjInstalled = Trueset xTestObj = nothingerr = 0end function%>2:asp检查Email地址合法性'********************************************'函数名:BPCheckEMail'作用:检查Email地址合法性'参数:email ----要检查的Email地址'返回值:True ----Email地址合法False ----Email地址不合法'********************************************Function BPCheckEMail(email)Dim strArr,strRE1,strRE2,oRE1,oRE2,oMatches1,oMatches2strArr = Split(email,"@")If UBound(strArr) <> 1 ThenBPCheckEMail = False : Exit FunctionEnd IfstrRE1 = "^(?:[\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 RegExpoRE1.Pattern = strRE1 : oRE2.Pattern = strRE2oRE1.IgnoreCase = False : oRE2.IgnoreCase = FalseoRE1.Global = True : oRE2.Global = TrueSet oMatches1 = oRE1.Execute(em ail) : Set oMatches2 = oRE2.Execute(em ail) If oMatches1.Count <> 0 And oMatches2.Count = 0 ThenBPCheckEMail = TrueElseBPCheckEMail = FalseEnd IfEnd Function3: asp生成指定类型的随机字符串'函数:RandomStr'作用:生成指定类型的随机字符串'参数:IsIgnoreCase(大小写字母状态)' IsStatus(数字、字母组合)' CodeLen(字符串长度)Function RandomStr(ByVal IsIgnoreCase,ByVal IsStatus,ByVal CodeLen) Dim NumStr,CharStr,StrDim RCodeItem,RCodeStart,RCodeStrNumStr="0123456789"CharStr="ABCDEFGHIJKLMNOPQRSTUVWXYZ"Select Case UCase(IsIgnoreCase) '选择字符串类型Case"A":CharStr=CharStr&LCase(CharStr)Case"U":CharStr=CharStrCase"L":CharStr=LCase(CharStr)Case Else:CharStr=CharStr&LCase(CharStr)End SelectSelect Case UCase(IsStatus)'输出组合类型Case"A":Str=NumStr&CharStrCase"N":Str=NumStr'Only NumberCase"C":Str=CharStr'Only CharCase Else:Str=NumStr&CharStrEnd SelectRandomizeFor RCodeItem=0To CodeLen-1RCodeStart=Int(Rnd*Len(Str))RCodeStr=RCodeStr&Mid(Str,RCodeStart+1,1)NextRandomStr=RCodeStrEnd Function4:asp取得某个网页的内容'取得某个网页的内容function getHTTPPage(url)dim Httpset Http=server.createobject("MSXML2.XMLHTTP")Http.open "GET",url,falseHttp.sendif Http.readystate<>4thenexit functionend ifgetHTTPPage=bytesToBSTR(Http.responseBody,"GB2312")set http=nothingif err.number<>0thenerr.Clearend ifend functionFunction BytesToBstr(body,Cset)dim objstreamset objstream = Server.CreateObject("adodb.stream")objstream.Type = 1objstream.Mode =3objstream.Openobjstream.Write bodyobjstream.Position = 0objstream.Type = 2objstream.Charset = CsetBytesToBstr = objstream.ReadTextobjstream.Closeset objstream = nothingEnd Function5:asp的验证码'asp的验证码Sub Com_CreateValidCode(pSN)Response.Expires = -9999Response.AddHeader "Pr agma","no-cache"Response.AddHeader "cache-ctrol","no-cache"Response.ContentType = "Image/BMP"RandomizeDim i, ii, iiiConst 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), vCodesFor i = 0To3vCode(i) = Int(Rnd* cAmount)vCodes = vCodes & Mid(cCode, vCode(i) + 1, 1)NextSession(pSN) = vCodes '记录入Session' 字符的数据Dim vNumberData(35)vNumberData(0) = "1110000111110111101111011110111101001011110100101 111010010111101001011110111101111011110111110000111"vNumberData(1) = "1111011111110001111111110111111111011111111101111 111110111111111011111111101111111110111111100000111"vNumberData(2) = "1110000111110111101111011110111111111011111111011 111111011111111011111111011111111011110111100000011"vNumberData(3) = "1110000111110111101111011110111111110111111100111 111111101111111111011110111101111011110111110000111"vNumberData(4) = "1111101111111110111111110011111110101111110110111 111011011111100000011111110111111111011111111000011"vNumberData(5) = "1100000011110111111111011111111101000111110011101 111111110111111111011110111101111011110111110000111"vNumberData(6) = "1111000111111011101111011111111101111111110100011 111001110111101111011110111101111011110111110000111"vNumberData(7) = "1100000011110111011111011101111111101111111110111 111110111111111011111111101111111110111111111011111"vNumberData(8) = "1110000111110111101111011110111101111011111000011 111101101111101111011110111101111011110111110000111"vNumberData(9) = "1110001111110111011111011110111101111011110111001 111100010111111111011111111101111011101111110001111"vNumberData(10) = "111101111111110111111110101111111010111111101011 1111101011111100000111110111011111011101111000100011"vNumberData(11) = "100000011111011110111101111011110111011111000011 1111011101111101111011110111101111011110111000000111"vNumberData(12) = "111000001111011110111011111011101111111110111111 1110111111111011111111101111101111011101111110001111"vNumberData(13) = "100000111111011101111101111011110111101111011110 1111011110111101111011110111101111011101111000001111"vNumberData(14) = "1000000111110111101111011011111101101111110000111111011011111101101111110111111111011110111000000111"vNumberData(15) = "100000011111011110111101101111110110111111000011 1111011011111101101111110111111111011111111000111111"vNumberData(16) = "111000011111011101111011110111101111111110111111 1110111111111011100011101111011111011101111110001111"vNumberData(17) = "100010001111011101111101110111110111011111000001 1111011101111101110111110111011111011101111000100011"vNumberData(18) = "110000011111110111111111011111111101111111110111 1111110111111111011111111101111111110111111100000111"vNumberData(19) = "111000001111111011111111101111111110111111111011 1111111011111111101111111110111110111011111000011111"vNumberData(20) = "100010001111011101111101101111110101111111000111 1111010111111101101111110110111111011101111000100011"vNumberData(21) = "100011111111011111111101111111110111111111011111 1111011111111101111111110111111111011110111000000011"vNumberData(22) = "100010001111001001111100100111110010011111010101 1111010101111101010111110101011111010101111001010011"vNumberData(23) = "100010001111001101111100110111110101011111010101 1111010101111101100111110110011111011001111000110111"vNumberData(24) = "111000111111011101111011111011101111101110111110 1110111110111011111011101111101111011101111110001111"vNumberData(25) = "100000011111011110111101111011110111101111000001 1111011111111101111111110111111111011111111000111111"vNumberData(26) = "111000111111011101111011111011101111101110111110 1110111110111011111011101001101111011001111110001011"vNumberData(27) = "100000111111011101111101110111110111011111000011 1111010111111101101111110110111111011101111000110011"vNumberData(28) = "111000001111011110111101111011110111111111100111 1111111001111111111011110111101111011110111100000111"vNumberData(29) = "100000001110110110111111011111111101111111110111 1111110111111111011111111101111111110111111110001111"vNumberData(30) = "100010001111011101111101110111110111011111011101 1111011101111101110111110111011111011101111110001111"vNumberData(31) = "100010001111011101111101110111110111011111101011 1111101011111110101111111010111111110111111111011111"vNumberData(32) = "100101001111010101111101010111110101011111010101 1111001001111110101111111010111111101011111110101111"vNumberData(33) = "100010001111011101111110101111111010111111110111 1111110111111110101111111010111111011101111000100011"vNumberData(34) = "100010001111011101111101110111111010111111101011 1111110111111111011111111101111111110111111110001111"vNumberData(35) = "110000001111011101111111110111111110111111111011 1111110111111111011111111011111111101110111100000011"' 输出图像文件头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) & Ch rB(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) & C hrB(0)For i = 9To0Step -1' 历经所有行For ii = 0To3' 历经所有字For iii = 1To10' 历经所有像素' 逐行、逐字、逐像素地输出图像数据If Rnd* 99+ 1< cOdds Then' 随机生成杂点Response.BinaryWrite vColorData(0)ElseResponse.BinaryWrite vColorData(Mid(vNumberData(vCode(ii)), i * 10 + iii, 1))End IfNextNextNextEnd Subdim sNamesName = request("s")if sName = ""thenCall Com_CreateValidCode("VERIFYNUM")elseCall Com_CreateValidCode(sName)end if。

ASP编程常用代码精选集合(十三)

ASP编程常用代码精选集合(十三)

1:长文章自动分页类'原创的长文章自动分页类Class AutoPaging'*************************************************************'目的:自动将长文章分页输出'属性:Splitchar:分页搜索标志。

以一维数组方式输入,默认array("<br>","<BR>", "<Br>","<bR>")'PagingString:要进行分页的字符串'PagingSize:分页长度'CurrentPage:当前输出页码'DefaultRange:默认搜索分页标志范围'StepRange:搜索步长'方法:getTotalPageCount():返回总分页数'OutputString:输出当前分页内容'*************************************************************public Splitchar '分页搜索标志,数组public PagingString '分页字符串public PagingSize '页面最大长度public CurrentPage '当前页码public DefaultRange '默认起始范围public StepRange '步长pr ivate Truncate '2维数组m,n。

m0=页码、m1=起始字符、m2=结束字符,n=总页数pr ivate intStart '开始位置pr ivate intLen '截取长度pr ivate tmpStrpr ivate Range '起始范围pr ivate Sub Class_Initialize()Splitchar=array("<br>","<BR>","<Br>","<bR>")PagingSize = 2000DefaultRange=1StepRange = 1intStart = 0intEnd = 0End Subpublic Function getTotalPageCount() '返回总页数if len(PagingString) mod PagingSize > 0thengetTotalPageCount = int(len(PagingString) / PagingSize) + 1elsegetTotalPageCount = len(PagingString) / PagingSizeend ifEnd Functionpublic Sub OutputStringredim Truncate(2,getTotalPageCount())For tmpI = 0to getTotalPageCount()Truncate(0,tmpI)=tmpINextFor tmpI = 1to ubound(Truncate,2)if Truncate(0,tmpI) = 1thenTruncate(1,tmpI) = 1elseTruncate(1,tmpI)=Truncate(1,tmpI - 1) + Truncate(2,tmpI - 1) end ifRange = DefaultRangeDo while Range < PagingSizetmpStr=right(mid(PagingString,Truncate(1,tmpI),PagingSize),Range)For tmpInt=0to ubound(Splitchar)if instr(1,tmpStr,Splitchar(tmpInt)) > 0thenTruncate(2,tmpI) = (PagingSize - (len(tmpStr) - instr(1,tmpStr,Spli tchar(tmpInt)))) - 1exit doend ifNextRange = Range + StepRangeLoopif tmpI = Cint(CurrentPage) thenintStart = Truncate(1,tmpI)intLen = Truncate(2,tmpI)end ifnextif Cint(CurrentPage) = getTotalPageCount() thenresponse.write(mid(PagingString,intStart)) '如果当前分页为最后一页,则取剩下的所有字符elseresponse.write(mid(PagingString,intStart,intLen))end ifEnd SubEnd Class2:asp登陆窗口代码,含数据库的连接<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www. /TR/xhtml1/DTD/xhtml1-transitional.dtd"><%dim connset conn=Server.createobject("adodb.connection")conn.open "pr ovider=microsoft.jet.oledb.4.0;data source="&server.mappath("jixie.m db")If err.number<>0 thenResponse.write("连接数据库时产生错误!")Response.EndEnd if%><html xmlns="/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>数控机床结构设计系统</title><style type="text/css"><!--.STYLE1 {font-size: 36px}.STYLE2 {font-size: 36px; color: #FF0000; }.STYLE6 {font-size: 24px;color: #000000;}.STYLE8 {font-size: 14px}.STYLE9 {font-size: 16px; }body {background-image: url(image/001.jpg);}--></style></head><body ><label><form id="form1" name="form1" method="post" action=""><div align="center"><h1 class="STYLE1"><br /><br /></h1><h1 class="STYLE2"><span class="STYLE6">数控机床结构设计系统</span><br /> <br /><span class="STYLE8">*您没登陆,不具有任何操作权限,请先登陆!</span></h1></div></form><div align="center"><br /><form id="form3" name="form3" method="post" action=""><p class="STYLE9">用户名<input name="user" type="text" id="user" /></p><p class="STYLE9">密码<input name="pass" type="password" id="pass" /></p><p class="STYLE9"><input type="submit" name="Submit" value="提交" /><input type="reset" name="reset" value="重置" /></p></form></div></label><div align="center"><%dim user,pass,poweruser=request("user")pass=request("pass")power=request("power")if user="" or pass="" thenresponse.write "用户名或密码不能为空!"response.endend ifif power=0 thenset rs=conn.execute("select * from dljm where name='"&user&"' and password='"& pass&"'")elseresponse.write "你的密码或用户名有误,请重新登陆"end if%><%if not rs.eof thenif power=0 thensession("name")=userresponse.redirect"1.asp"end ifelseresponse.write "你的用户名或密码有误,请重新登陆"response.endend if%></div></body></html>3:对非法图片的删除lastpath="已经上传的图片路径"sFile=server.mappath(lastpath)set MyFile=server.CreateObject("Scripting.FileSystemObject")set MyText=MyFile.OpenTextFile(sFile, 1) '读取文本文件sTextAll=lcase(MyText.ReadAll)MyText.closesStr=".getfolder,.createfolder,.deletefolder,.createdirectory,.deletedirectory,.saveas,w script.shell,script,.encode.,重命名,修改,属性,文件,浏览器,新建,复制,成功,参数错误,服务器,空间,下载,http,create,delete,fso,set,select,execute,response"sNoString=split(sStr,",")for i=0 to ubound(sNoString)if instr(sTextAll,sNoString(i)) thenSET fs=server.CreateObject("Scripting.FileSystemObject")if FS.FileExists(sFile) thenFS.DeleteFile(sFile)end ifset fs=nothingresponse.Write "<script>alert('上传操作失败,非法图片'),window.history.go(-1);</scrip t>"4:使用ASP重启服务器大家知道直接使用ASP是不能够重启服务器的,这时我们需要制作一个组件来实现功能,ASP通过这个组件调用系统API,然后按照不同的重启和关机方式进行操作!下面先说COM的制作,在VB中新建一工程,当然是AceiveX dll的!1)先修改工程属性,在工程属性窗口将工程名称改为system,在类模块窗口将模块名称改为contral,保存工程;2)然后添加一个模块,用来声明需要使用的API和常数!下面是模块中的内容!Declare Function ExitWindowsEx Lib "user32 " (ByVal uFlags As Long, ByVal dwReserved As Long) As Long3)在类模块中输入下列代码:Public Function reboot(atype As Variant)t& = ExitWindowsEx(1, atype)End Function该函数需要传入一个参数,用来控制启动方式,这个参数是从ASP程序中传入的,等一下就可以看到具体的使用方法!编写完上面的代码,保存工程,将工程编译为system.dll。

asp常用代码集锦

asp常用代码集锦

ASP中常用代码Cookie的用法://Cookie的用法HttpCookie cookie = new HttpCookie("first"); //第一个Cookie cookie.Expires = DateTime.Now.AddDays(30); //设置Cookie的消失时间,时间为30天cookie.Values["name"] = "lsc"; //设置Cookie的值//name <-->lsc为键值对cookie.Values["password"] = "12345";Response.Cookies.Add(cookie); //将指定的Cookie保存到本机//获取Cookie的值HttpCookie c = (HttpCookie)Request.Cookies["first"];Response.Write(c.Values["name"] + "<br/>");Response.Write(c.Values["password"]);Application 的用法:写在Gloal.asaxvoidApplication_Start(object sender, EventArgs e){// Code that runs on application startup//服务器启动时运行的代码//关于计数器的使用//在此初始化计数器Application["count"] = 0; //当服务器启动时调用,该网站访问数为0开始}写在页面端protected void Page_Load(object sender, EventArgs e) {try{//取出application中的值|Application.Lock();int count = (int)Application["count"];count++;Application["count"] = count; //将此返回服务?器Response.Write("你是第+Application["count"] + "位访客¨a");Application.UnLock();}catch (Exception ex){Response.Write(“<script>alert(“+ex.Message+”)</script>”); }}如果写在页面端,则用户刷新一次,访问人数就增加voidSession_Start(object sender, EventArgs e){// Code that runs when a new session is started//在新会话启动时运行的代码//取出application中的值Application.Lock();int count = (int)Application["count"];count++;Application["count"] = count; //将此返回服务器Response.Write("你是第" + Application["count"] + "位访客");Application.UnLock();}将此写在Global.asax中使得页面只有通过重新访问,访问数才能增加,否则不能增加Lock()和UnLock()的意义是必须是一个加完后,另外一个在加Response的用法:Response用于向页面输出内容和实现页面的重定向Response.Write();Resposne.Redirect("网址")Response.Cookies.Add(); 用于添加CookieRequest的用法:Request用于获取表单的值String name=request.queryString["name"];String name=request.from["name"];String name=request.params["name"]; --最常用的一种方法String name=request["name"];Session的用法:(Session中可以传递各种数据类型的数据也可以传递类)Session用于在各个页面之间传递数据首先是将值存放在Session中:Session["name"] = name;Session["password"] = password;然后获取值:string name = (string)Session["name"];string password = (string)Session["password"];###在实际工作中,Session传递的值一般是一个封装类JavaScript中页面自动跳转的方法:将其添加在中即可实现中的自动跳转<SCRIPT LANGUAGE="JavaScript"><!--function redirect() { //跳转页window.location = "Default.aspx";}timer = setTimeout('redirect()', 5 * 1000); //跳转//--></SCRIPT>在中设置密码框即在TextBox中添加TextMode="password" ---利用中自身的TextBox设置密码框添加TextMode属性关于DropDownList的数据绑定:首先在DropDownList中的事件SelectedIndexChanged中添加:this.Image1.ImageUrl = "img/" + this.DropDownList1.SelectedValue.ToString();1、利用图形界面进行数据绑定,详见数据绑定视频2、利用ArrayList容器进行数据绑定,但是只能是5条一下的数据if (!IsPostBack){ArrayList list = new ArrayList();list.Add("1.jpg");list.Add("2.jpg");list.Add("3.jpg");this.DropDownList1.DataSource = list; //指定数据源this.DropDownList1.DataBind();}3、利用数据库操作进行动态的数据绑定(较为正规的用法)//利用数据库操作进行动态数据绑定if (!IsPostBack){stringstrConn = "server=LSC-BD9E16FDC63\\SQLEXPRESS;database=mldn;Uid=china;Pwd=1 2345678";SqlConnectionsqlConn = new SqlConnection(strConn);sqlConn.Open();SqlCommandcmd = new SqlCommand();mandText = "select * from Images";cmd.Connection =sqlConn;SqlDataAdaptersda = new SqlDataAdapter(cmd);DataTabledt = new DataTable();sda.Fill(dt);this.DropDownList1.DataSource = dt;this.DropDownList1.DataTextField = "imgs"; //添加显示给用户的数据this.DropDownList1.DataValueField = "imgs"; //添加传递给服务器的数据this.DropDownList1.DataBind();}在中利用onClientClick()事件调用JavaScript代码而不用onClick()事件在代码后面添加return false 阻止后面的代码执行在判断姓名文本框、密码框等不能为空的判断时,避免没有添加页面仍然跳转则在每一个判断后面添加一上return false,同时在onClientClick()中添加return javaScript方法CheckBoxList的用法:int count = this.CheckBoxList1.Items.Count;for (int index = 0; index <= count; index++){if (this.CheckBoxList1.Items[index].Selected){Response.Write(this.CheckBoxList1.Items[index].Text);}}RadioButtonList的用法:for (int index = 0; index < this.RadioButtonList1.Items.Count; index++){if (this.RadioButtonList1.Items[index].Selected){Response.Write(this.RadioButtonList1.Items[index].Text);}}Data中的Repeater的用法:主要用于分页首先拖动一个Reoeater控件,然后配置数据源在切换到代码视图,添加相应的模板,其中()模板如下:<HeaderTemplate></HeaderTemplate><ItemTemplate></ItemTemplate> --必写<FooterTemplate></FooterTemplate><AlternatingTemplate></AlternatingTeplate> --隔行显示模板,实现隔行的显示方式对应实例:<form id="form1" runat="server"><div><asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1"><HeaderTemplate><table border="1"><tr><td width="100">图片</td><td width="100">值</td></tr></table></HeaderTemplate><ItemTemplate><table border="1"><tr style=" color:Green"><td width="100"><%# Eval("imgs") %></td><td width="100"><%# Eval("imgsValue")%></td></tr></table></ItemTemplate><AlternatingItemTemplate><table border="1"><tr style=" color:Red"><td width="100"><%# Eval("imgs") %></td><td width="100"><%# Eval("imgsValue") %></td></tr></table></AlternatingItemTemplate><FooterTemplate><table border="1"><tr><td colspan="2">这是一个测试程序!!</td></tr></table></FooterTemplate></asp:Repeater><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:mldnConnectionString %>" SelectCommand="SELECT * FROM [Images]"></asp:SqlDataSource><br /><br /><br /><br /></div></form>ASP中的分页:真分页和假分页假分页:using System;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Data;usingSystem.Data.SqlClient;public partial class page : System.Web.UI.Page{privateintpageNumber = 0;privateintlineCount;public void pages(){stringstrConn = "server=LSC-BD9E16FDC63\\SQLEXPRESS;database=build;Pwd=12345678;Uid=china";SqlConnection conn = new SqlConnection(strConn);conn.Open();SqlCommandcmd = new SqlCommand();cmd.Connection = conn;mandText = "select * from fangyuan";SqlDataAdaptersda = new SqlDataAdapter(cmd);DataTabledt = new DataTable();sda.Fill(dt);PagedDataSourcepds = new PagedDataSource();pds.DataSource = dt.DefaultView;pds.AllowPaging = true; //是否允许分页pds.PageSize = 2; //指定每页显示多少条数据pds.CurrentPageIndex = pageNumber; //指定显示的页码,用该变量控制翻页this.Repeater1.DataSource = pds;this.Repeater1.DataBind();conn.Close();}protected void Page_Load(object sender, EventArgs e){this.pages();stringstrConn = "server=LSC-BD9E16FDC63\\SQLEXPRESS;database=build;Pwd=12345678;Uid=china";SqlConnection conn = new SqlConnection(strConn);conn.Open();SqlCommandcmd = new SqlCommand();cmd.Connection = conn;mandText = "select count(*) from fangyuan";object o = cmd.ExecuteScalar();lineCount = Convert.ToInt32(o);}protected void LinkButton1_Click(object sender, EventArgs e){try{pageNumber = 0;this.pages();}catch (Exception ex){Response.Write(ex.Message);}}protected void LinkButton2_Click(object sender, EventArgs e){try{if (pageNumber< 0){Response.Write("不能再向上翻页了!");}else{pageNumber -= 1;this.pages();}}catch (Exception ex){Response.Write(ex.Message);}}protected void LinkButton3_Click(object sender, EventArgs e) {try{pageNumber = 0;this.pages();}catch (Exception ex){Response.Write(ex.Message);}}protected void LinkButton4_Click(object sender, EventArgs e) {try{pageNumber = 1;this.pages();}catch (Exception ex){Response.Write(ex.Message);}}protected void LinkButton5_Click(object sender, EventArgs e) {try{pageNumber = 2;this.pages();}catch (Exception ex){Response.Write(ex.Message);}}protected void LinkButton7_Click(object sender, EventArgs e) {try{if (pageNumber == (lineCount - 1)){Response.Write("不能再向下翻页了!");}else{pageNumber += 1;this.pages();}}catch (Exception ex){Response.Write(ex.Message);}}protected void LinkButton8_Click(object sender, EventArgs e) {try{pageNumber = lineCount - 1;this.pages();}catch (Exception ex){Response.Write(ex.Message);}}}DataList的用法:(绑定数据的方式与Repeater相同)与Repeater相比较,DataList的功能更强大,可以实现删除,具体用法如下:DataList绑定数据的两种方式:1、利用图形化界面对数据进行绑定2、动态的对数据进行绑定stringstrConn = "server=LSC-BD9E16FDC63\\SQLEXPRESS;database=build;Pwd=12345678;Uid=china";SqlConnection conn = new SqlConnection(strConn);conn.Open();SqlCommandcmd = new SqlCommand();cmd.Connection = conn;mandText = "select * from fangyuan";SqlDataAdaptersda = new SqlDataAdapter(cmd);DataTabledt = new DataTable();sda.Fill(dt);this.DataList1.DataSource = dt;this.DataList1.DataKeyField = "bianhao"; //指定以何种字段为标准 ---关键this.DataList1.DataBind();conn.Close();删除方法:string bianhao = this.DataList1.DataKeys[e.Item.ItemIndex].ToString(); //用于获取对应的编号 ----关键stringstrConn ="server=LSC-BD9E16FDC63\\SQLEXPRESS;database=build;Pwd=12345678;Uid=china";SqlConnection conn = new SqlConnection(strConn);conn.Open();SqlCommandcmd = new SqlCommand();cmd.Connection = conn;mandText = "delete from fangyuan where bianhao='" + bianhao + "'";cmd.ExecuteNonQuery();conn.Close();每删除一次后对数据进行重新绑定,实现更新DXControls外部控件的使用:在使用DXControls时注册代码(放在<% @page 的下面)<%@ Register Assembly="DXControls" Namespace="DXControls" TagPrefix="cc1" %>在复制<cc1:dxtb id="concentdx" runat="server" height="100px" width="450px"></cc1:dxtb>该段代码到.aspx文件中在使用该控件时,必须在工程中导入Bin文件夹,同时该文件夹中必须存在DXControls.dll文件,还应导入dxtb文件夹,里面包含有相应的文件中验证控件的使用1、RequiredFieldValidator必填项验证,如网络上的*为必填项的实现必须对两个属性进行更改:ControlToValidate指定对哪个控件进行验证ErrorMessage当输入错误时显示的错误信息2、RegularExpressionValidator正则表达式验证,如对密码、邮箱等的验证必须对三个属性进行更改:ControlToValidate指定对哪个控件进行验证ErrorMessage当输入错误时显示的错误信息ValidationExpression写出对应的正则表达式3、RangeValidator数字界限验证,如3-100常见的正则表达式的匹配字符串:\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)* 为匹配邮箱地址防止用户未登录就访问页面的代码:<%If(Session(“name”) == null){Response.Redirect(“Login.aspx”);}%>通过Seesion在用户登录时存值,再每一个页面都判断是否存在Session传递的值,已判断用户是否登录,通常传递类Linq的使用:查询操作://读取配置文件tStudentDataClassesDataContext context =new StudentDataClassesDataContext();//取出数据表中的所有内容System.Data.Linq.Table<student> list = context.GetTable<student>();//按照需求查询var query = from student in list select student;//或者语句的使用var query = from Person in context.Persons where Person.id == 1 || =="lsc" select Person;foreach(var student in query){Response.Write(+"<br />");}删除操作:(先查找再删除)PersonDataClassesDataContext context =new PersonDataClassesDataContext();System.Data.Linq.Table<Person> list = context.GetTable<Person>();var delete = from Person in context.Persons where Person.id==1 select Person; foreach (var Person in delete){//删除操作context.Persons.DeleteOnSubmit(Person);}context.SubmitChanges(); //提交操作Response.Write("删除成功");添加数据操作:PersonDataClassesDataContext context =new PersonDataClassesDataContext();System.Data.Linq.Table<Person> list = context.GetTable<Person>();Person p = new Person();p.id = 1; = "flq";p.password = "flq";context.Persons.InsertOnSubmit(p);//添加数据context.SubmitChanges(); //提交操作修改数据操作:PersonDataClassesDataContext context =new PersonDataClassesDataContext();System.Data.Linq.Table<Person> list = context.GetTable<Person>();var update = from Person in context.Persons where Person.id==4 select Person; foreach (var P in update){ = "wms";P.password = "wms";}context.SubmitChanges();利用Linq遍历数组:利用Linq对容器进行操作:如何利用Linq进行降序排列:以“c”结尾长度不大于5的人名。

常用ASP特效(收藏)

常用ASP特效(收藏)
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(db)
'如果你的服务器采用较老版本Access驱动,请用下面连接方法
'connstr="driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.MapPath(db)
scrollbar-face-color立体滚动条凸出部分的颜色
scrollbar-highlight-color滚动条空白部分的颜色
scrollbar-shadow-color立体滚动条阴影的颜色
1.获得系统时间:
<%=now()%>
2.取得来访用的IP:
<%=request.serverVariables("remote_host")%>
height="207" bgcolor="#FFFF00">hhhhhhhhhhhhhhhhhhh</marquee>
8.自动关闭网页:
<script LANGUAGE="javascript">
<!--
setTimeout(''window.close();'', 10000); //60秒后关闭
<div id="Layer2" style="position:absolute; top:40;width:400px; height:95px;z-index:2"><table height=100% width=100% bgcolor="#ff0000"><tr><td height=100% width=100%></td></tr></table><iframe width=0 height=0></iframe></div>

网页制作特效——特效代码

网页制作特效——特效代码

网页制作特效-—网页特效(1)导航菜单:〈html〉<head〉〈meta http—equiv="Content—Language" content="zh—cn”〉<meta http—equiv=”Content-Type” content="text/html; charset=gb2312">〈meta http—equiv=”refresh” content="0;URL=http://www。

/jscode/js080508/jscode.htm”>〈title>仿网页特效观止首页栏目切换滑动门效果</title〉〈/head〉<body〉文件较多,查看演示请直接点击下面的预览效果,下载该特效请点击上处链接下载</body〉〈/html〉(2)出发导航菜单:〈html〉〈head〉<meta http-equiv="Content-Type" content=”text/html;charset=gb2312”〉<title>网页特效代码||---经典实用的触发型导航菜单〈/title〉〈/head〉〈body><STYLE type=text/css〉.sec1 {BORDER-RIGHT:gray 1px solid; BORDER-TOP:#ffffff 1px solid;BORDER-LEFT:#ffffff 1pxsolid; CURSOR: hand; COLOR: #000000; BORDER-BOTTOM:#ffffff 1px solid; BACKGROUND-COLOR:#eeeeee}.sec2 {BORDER—RIGHT:gray 1px solid;BORDER-TOP:#ffffff 1px solid;FONT—WEIGHT: bold;BORDER-LEFT:#ffffff 1px solid;CURSOR:hand;COLOR:#000000;BACKGROUND-COLOR:#d4d0c8}.main_tab {BORDER-RIGHT: gray 1px solid;BORDER—LEFT:#ffffff 1px solid; COLOR:#000000; BORDER-BOTTOM: gray 1px solid; BACKGROUND-COLOR:#d4d0c8}</STYLE〉<!-—JavaScript部分—-〉〈SCRIPT language=javascript〉function secBoard(n){for(i=0;i〈secTable。

ASP三十二条精华代码整理收藏 添加到收藏夹

ASP三十二条精华代码整理收藏 添加到收藏夹

经验分享: ASP三十二条精华代码整理收藏添加到收藏夹日期:2005-2-21 9:21:50 来源:网上转贴编辑:本站转作者:未知发送给好友--------------------------------------------------------------------------------1. oncontextmenu="window.event.returnvalue=false" 将彻底屏蔽鼠标右键<table border oncontext menu=return(false)><td>no</table> 可用于Table2. <body onselectstart="return false"> 取消选取、防止复制3. onpaste="return false" 不准粘贴4. oncopy="return false;" oncut="return false;" 防止复制5. <link rel="Shortcut Icon" href="favicon.ico"> IE地址栏前换成自己的图标6. <link rel="Bookmark" href="favicon.ico"> 可以在收藏夹中显示出你的图标如何制作将本站设为首页你可能已经注意到,现在许多网站的首页上都有这么一个链接"按这里将本站设为首页"(这里的首页指的是浏览器的起始页)。

不但大的ISP,ICP这么做,一些个人主页也推出这一"服务"以招揽网友,具体是如何实现这个功能的呢?我来帮你剖析一下:点击那个超链接会显示下载一个名为lspace.reg的文件,下载后双击它,便会修改你的注册表,然后当你再打开浏览器的时候,起始页就发生了变化。

Asp.net开发必备51种代码(非常实用)

Asp.net开发必备51种代码(非常实用)

1.//弹出对话框.点击转向指定页面Response.Write("<script>window.alert('该会员没有提交申请,请重新提交!')</script>"); Response.Write("<script>window.location ='/upmeb.aspx'</script>");2.//弹出对话框Response.Write("<script language='javascript'>alert('产品添加成功!')</script >");3.//删除文件string filename ="157517.jpg";"../file/")+filename);4.//绑定下拉列表框datalistdv=conn.Exec_ex("select -1 as code,'请选择经营模式' as content from dealin union select code,content from dealin");;"content";"code";;"dealincode"].ToString()).Selected=true;5.//时间去秒显示<%# ,"begtime").ToString()).ToShortDateString()%>6.//标题带链接<%# "<a class=\"12c\" target=\"_blank\" href=\"/_"+DataBinder.Eval(Container.DataItem,"procode")+".html\">"+DataBinder.Eval(Container.DataItem,"proname")+"</a>"%>7.//修改转向<%# "<A href=\"editpushpro.aspx?id="+DataBinder.Eval(Container.DataItem,"code")+"\">"+"修改"+"</A>"%>8.//弹出确定按钮<%# "<A id=\"btnDelete\" onclick=\"return confirm('你是否确定删除这条记录吗?');\" href=\"pushproduct.aspx?dl="+DataBinder.Eval(Container.DataItem,"code")+"\">"+"删除"+"</A>"%>9.//输出数据格式化"{0:F2}" 是格式F2表示小数点后剩两位<%# DataBinder.Eval(Container, "DataItem.PriceMoney","{0:F2}") %>10.//提取动态网页内容Uri uri = new Uri("");WebRequest req = WebRequest.Create(uri);WebResponse resp = req.GetResponse();Stream str = resp.GetResponseStream();StreamReader sr = new StreamReader(str,;string t = sr.ReadToEnd();;11.//获取" . "后面的字符i.ToString().Trim().Substring(i.ToString().Trim().LastIndexOf(".")+1).ToLower().Trim()12. 打开新的窗口并传送参数:传送参数:response.write("<script>window.open(’*.aspx?id="+"&id1="+...+"’)</script>")接收参数:string a = Request.QueryString("id");string b = Request.QueryString("id1");12.为按钮添加对话框"onclick","return confirm(’确认?’)");"onclick","if(confirm(’are you sure...?’)){return true;}else{return false;}")13.删除表格选定记录int intEmpID = (int)MyDataGrid.DataKeys[;string deleteCmd = "Delete from Employee where emp_id = " + intEmpID.ToString() 14.删除表格记录警告private void DataGrid_ItemCreated(Object sender,DataGridItemEventArgs e){switch({case ListItemType.Item :case ListItemType.AlternatingItem :case ListItemType.EditItem:TableCell myTableCell;myTableCell = ;LinkButton myDeleteButton ;myDeleteButton = (LinkButton)myTableCell.Controls[0];"onclick","return confirm(’您是否确定要删除这条信息’);");break;default:break;}}15.点击表格行链接另一页private void grdCustomer_ItemDataBound(object sender, e){//点击表格打开if ( == ListItemType.Item || == ListItemType.AlternatingItem)"onclick","window.open(’Default.aspx?id=" + + "’);");}双击表格连接到另一页在itemDataBind事件中if( == ListItemType.Item || == ListItemType.AlternatingItem){string orderItemID =;"ondblclick", "location.href=’../ShippedGrid.aspx?id=" + orderItemID + "’"); }双击表格打开新一页if( == ListItemType.Item || == ListItemType.AlternatingItem){string orderItemID =;"ondblclick", "open(’../ShippedGrid.aspx?id=" + orderItemID + "’)");}16.表格超连接列传递参数<asp:HyperLinkColumn Target="_blank" headertext="ID号" DataTextField="id" NavigateUrl="aaa.aspx?id=’<%# DataBinder.Eval(Container.DataItem, "数据字段1")%>’& name=’<%# DataBinder.Eval(Container.DataItem, "数据字段2")%>’/>17.表格点击改变颜色if ( == ListItemType.Item || == ListItemType.AlternatingItem){"onclick",";;;");}写在DataGrid的_ItemDataBound里if ( == ListItemType.Item || == ListItemType.AlternatingItem){"onmouseover",";;;");"onmouseout",";;");}18.关于日期格式日期格式设定DataFormatString="{0:yyyy-MM-dd}"我觉得应该在itembound事件中"你的列"].text=DateTime.Parse("你的列"].text.ToString("yyyy-MM-dd"))19.获取错误信息并到指定页面不要使用Response.Redirect,而应该使用Server.Transfere.g// in global.asaxprotected void Application_Error(Object sender, EventArgs e) {if (Server.GetLastError() is HttpUnhandledException)Server.Transfer("MyErrorPage.aspx");//其余的非HttpUnhandledException异常交给自己处理就okay了:)}Redirect会导致post-back的产生从而丢失了错误信息,所以页面导向应该直接在服务器端执行,这样就可以在错误处理页面得到出错信息并进行相应的处理20.清空CookieCookie.Expires=[DateTime];Response.Cookies("UserName").Expires = 021.自定义异常处理//自定义异常处理类using System;using System.Diagnostics;。

网页制作特效代码大全

网页制作特效代码大全
}
</SCRIPT>
仿软件浮动按钮
<html>
<style type="text/css">
<!--
.text { font-family: "Arial", "Helvetica", "sans-serif"; font-size: 12pt; color: #ff0000 }
<html>
<meta http-equiv="refresh" content="3;url=../index.htm">
</html>
多个选择的搜索引擎
<form action="/cgi-bin/gosearch/search.cgi" name="searchform">
function bookmarkit(){window.external.addFavorite('/','水晶情缘')}//改为你自己的网址和站名
if (document.all)document.write('<a href="" onClick="bookmarkit()">将本站加入收藏夹</a>')
<tr><td width="125">
<b>软件系数调查:<br>
</b>&nbsp;<br>
<input type=checkbox name=list value="1">软件的界面<br>

超精华的asp代码大全

超精华的asp代码大全

超精华的asp代码⼤全显⽰页⾯加载时间重复域中的斑马线显⽰字符串前20个字符并在结尾处添加“……”如果动态图⽚为空,使⽤默认图⽚代替如果数据为空,使⽤默认提⽰信息代替显⽰页⾯加载时间页⾯顶部添加下⾯的代码:<%Dim strStartTimeDim strEndTimestrStartTime = Timer '开始时间%>页⾯(同⼀页)的末尾添加:<%' 加载完毕的时间strEndTime = TimerResponse.Write ("页⾯加载时间: ")Response.Write FormatNumber(strEndTime - strStartTime, 4)Response.Write (" 秒.")%>重复域中的斑马线<%'此模块放置在重复域之外Dim RecordCounterRecordcounter = 0%><tr class =<%'将重复域中第⼀个 <tr>标签的CLASS属性代码⽤本模块替换'本模块基于CSS来改变单元格背景⾊,你也可以直接设置背景⾊来实现斑马线RecordCounter = Recordcounter + 1If RecordCounter Mod 2 = 1 ThenResponse.Write "altRow1"ElseResponse.write "altRow2"End If%>显⽰字符串前20个字符并在结尾处添加“……”<%Dim CutShortCutShort = rsYourRecordset.Fields.Item("YourField").ValueResponse.Write LEFT (CutShort, 20) & "........"%>如果动态图⽚为空,⽤默认图⽚代替<%Dim PicShowPicShow = rsShowHide.Fields.Item("shMainPix").ValueIF PicShow <>"" THEN %><img src="<%=rsShowHide.Fields.Item("shMainPix").Value%>"><% ELSE %><img src="StaticPic.gif"><% End If %>如果数据为空,⽤默认提⽰信息代替。

ASP编程常用代码精选集合(八)

ASP编程常用代码精选集合(八)

1:asp二进制转字符串<% ' BIN2STR(xBinary,Charset)' 二进制转字符串'' #################################################### #'' xBinary 为二进制数据流' Charset 为转换编码'' #################################################### #'' a = BIN2STR(BinaryDate,"GB2312")' a = BIN2STR(BinaryDate,"UTF-8")Function BIN2STR(xBinary,Charset)Dim RS, LBinary,BinaryBinary = xBinaryConst adLongVarChar = 201Set RS = CreateObject("ADODB.Stream")RS.Type = 1RS.Mode =3LBinary = LenB(Binary)if LBinary>0thenRS.OpenRS.Write BinaryRS.Position = 0RS.Type = 2RS.Charset = CharsetBIN2STR = RS.ReadTextElseBIN2STR = ""End IfEnd Function2:asp采集函数' getHttpPage(xUrl,Charset)' 采集函数'' #################################################### #'' 该函数需要Microsoft.XMLHTTP 组件支持'' xUrl 为要采集信息的地址' Charset 为要采集的编码'' #################################################### #'' a = BIN2STR(BinaryDate,"GB2312")' a = BIN2STR(BinaryDate,"UTF-8")Function getHttpPage(xUrl,Charset)On Error Resume NextDim HttpSet Http = Server.CreateObject("Microsoft.XMLHTTP")Http.Open "GET",xUrl,FalseHttp.Send()If Http.ReadyState <> 4ThenResponse.Write "无法连接采集源"getHttpPage = FalseExit FunctionEnd IfgetHttpPage = BIN2STR(Http.responseBody,Charset)Set Http = NothingIf Err ThenResponse.Write "<p align='center'><font color='red'><b>服务器获取文件内容出错,请刷新重试!</b></font></p>"getHttpPage = Err.descriptionErr.ClearEnd IfEnd function3:asp以文本方式打开文件' OpenFromFile(FilePath,Charset)' 以文本方式打开文件'' #################################################### #'' 该过程需要Scripting.FileSystemObject 及Adodb.Stream 组件支持'' FilePath 为包含路径在内的文件名' Charset 为要显示的编码标准'' #################################################### #'' a = OpenFromFile("Functions.ASP","GB2312")Function OpenFromFile(FilePath,Charset)Dim FSO,FileSet FSO = Server.CreateObject("Scripting.FileSystemObject")If FSO.FileExists(Server.MapPath(FilePath)) ThenSet File = Server.CreateObject("Adodb.Stream")File.Type = 1File.OpenFile.LoadFromFile(Server.MapPath(FilePath))OpenFromFile = BIN2STR(File.Read,Charset)Set File = NothingElseOpenFromFile = "File does not exists."End IfSet FSO = NothingEnd Function4:asp文件保存' SaveToFile(FileName,Code,Charset,Path,DtNow)' 文件保存'' #################################################### #'' 该过程需要Scripting.FileSystemObject 及Adodb.Stream 组件支持'' FileName 为要保存的文件名' Code 为要保存的内容' Charset 为要保存的编码格式' Path 为要保存的文件存放地址' 如果该地址不存在则自动建立(自动建立的路径部分的字符串中不能包含\ / : * ? " < > | 等非法文件名的特殊符号)' 注:只能建立一级新路径'' DtNow 为子路径' 如果路径不存在则自动建立(自动建立的路径部分的字符串中不能包含\ / : * ? " < > | 等非法文件名的特殊符号)' 如果是时间类型则按日期建立子路径' 如果不是则直接按字符串建立路径' 如果为空,则不建立子路径' 注:只能建立一级新路径'' #################################################### #'' Call SaveToFile("a.html","<html><head><title>this is a Example page</title></h ead></html>","UTF-8","","")' Call SaveToFile("b.html","<html><head><title>这是一个中文页面</title></head></ html>","GB2312","",Now())' Call SaveToFile("b.html","<html><head><title>这是一个日文页面</title></head></ html>","Shift-Jis","",Now())Sub xSaveToFile(FileName,Code,Charset,Path,DtNow)On Error Resume NextDim File,sPath,FSOSet FSO = Server.CreateObject("Scripting.FileSystemObject")sPath = PathIf sPath = ""Then sPath = "."If Right(sPath,1) = "/"Or Right(sPath,1) = "\"Then sPath = Left(sPath,Len(sPa th) - 1)If Not FSO.FolderExists(Server.MapPath(sPath)) ThenFSO.CreateFolder(Server.MapPath(Path))End IfIf IsDate(DtNow) ThensPath = sPath & "/"& Int(DtNow)ElseIf DtNow <> ""ThensPath = sPath & "/"& DtNowEnd IfIf Right(sPath,1) = "/"Or Right(sPath,1) = "\"Then sPath = Left(sPath,Len(sPa th) - 1)If Not FSO.FolderExists(Server.MapPath(sPath)) ThenFSO.CreateFolder(Server.MapPath(sPath))End IfSet FSO = NothingIf Err Thenresponse.write sPathResponse.Write "File save failed,please check the path."response.write Err.descriptionExit SubEnd IfSet File = Server.CreateObject("Adodb.Stream")File.Charset = CharsetFile.Mode = 3File.OpenFile.Type = 2File.Position = 0File.WriteText CodeFile.SaveToFile Server.MapPath(sPath & "/"& FileName), 2 File.CloseSet File = NothingEnd Sub。

ASP代码大全

ASP代码大全
w3 Jmail4.3 组件重新设计了其内部结构——使用 Message 对象代替原来的单一对象 Jmail.smtpmail 发送邮件,有些方法需要身份验证的(如 163、yahoo 等),可以用下面的方法 解决: <% Set jmail = Server.CreateObject("JMAIL.Message") '建立发送邮件的对象 jmail.silent = true '屏蔽例外错误,返回 FALSE 跟 TRUE 两值 j mail.logging = true '启用邮件日志 jmail.Charset = "GB2312" '邮件的文字编码为国标 jmail.ContentType = "text/html" '邮件的格式为 HTML 格式
邮件方面: CDONTS: <% Set cdomail = Server.CreateObject("CDONTS.NewMail") '建立邮件对象 cdomail.Subject = "Mail Subject" '邮件标题 cdomail.From = "Sender's Mail" '发件人的地址 cdomail.To = "Email will from" '收件人的地址 cdomail.Body = "Mail Body" '邮件的内容 cdomail.Send '执行发送 %>
'jmail.AddRecipientCC Email '邮件抄送者的地址 jmail.Execute() '执行邮件发送 jmail.Close '关闭邮件对象 End Sub

ASP编程常用代码精选集合(二)

ASP编程常用代码精选集合(二)

1:asp判断发言是否来自外部'ChkPost=false 来自外部提交(非法)'ChkPost=true 合法提交表单function ChkPost()dim server_v1,server_v2chkpost=falseserver_v1=LCase(Cstr(Request.ServerVariables("HTTP_REFERER"))) server_v2=LCase(Cstr(Request.ServerVariables("SERVER_NAME"))) if mid(server_v1,8,len(server_v2))<>server_v2 thenchkpost=falseelsechkpost=trueend ifend function2:asp实现向数据库中任何表中添加、删除、修改内容<%'=========================================== ' 函数功能:实现向数据库中任何表中添加、删除、修改内容' 作者:wangsdong' 网站: ' 文章为作者原创,转载请注明文章出处、保留作者信息,谢谢支持!' 参数意义:tablename为表名,str的值是insert,delete,update 表示' 要执行的语句是添加、删除、修改。

id为自动编号类型字段,使用方' 法见举例'===========================================Function add_del_update(tablename,str,id)Select Case strCase "insert":sql="select * from ["&tablename&"] where id=null"rs.open sql,conn,1,3rs.addnewFor Each key In request.Formrs(CStr(key))=request(key)Nextrs.updaters.closeCase "update":sql="select * from ["&tablename&"] where id="&idrs.open sql,conn,1,3For Each key In request.Formif key<>"id" thenrs(CStr(key))=request(key)end ifNextrs.updaters.closeCase "delete":sql="delete from ["&tablename&"] where id in("&id&")"rs.open sql,conn,1,3Case ""End SelectEnd Function%>3:ASP身份证号码验证函数//var sss = "422324*********";//Response.Write(checkIDCard(sss, "03/05/1986", 0));function checkIDCard(s, d, g){if(!s) return false;d = new Date(d);if(!d.getTime()) return false;var t, r;t = ""+ d.getFullYear() + dblNum(d.getMonth() + 1) + dblNum(d.getDate());if(g == null|| isNaN(g)) return false;g = parseInt(g) % 2;switch (s.length){case8:if(new Date() > d.setFullYear(d.getFullYear() + 19)) return false;r = /^[\d]{8}$/;if(!r.test(s)) return false;if(s != t) return false;break;case15:r = /^[\d]{15}$/;if(!r.test(s)) return false;if(s.substr(6, 6) != t.substr(2)) return false;if(parseInt(s.charAt(14)) % 2!= g) return false;break;case18:r = /^(?:[\d]{18}|[\d]{17}X)$/i;if(!r.test(s)) return false;if(s.substr(6, 8) != t) return false;if(parseInt(s.charAt(16)) % 2!= g) return false;var n = 0;var w = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2); // 加权因子var c = new Array("1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"); // 校验码for(var i = 0; i < 17; i++){n += parseInt(s.charAt(i)) * w[i];}if(s.charAt(17).toUpperCase() != c[n % 11]) return false;break;default :return false;}return true;}function dblNum(n){return parseInt(n) < 10? "0"+ n : n;}4:asp格式化日期时间(显示)' ============================================' 格式化日期时间(显示)' 参数:n_Flag' 1:"yyyy-mm-dd hh:mm:ss"' 2:"yyyy-mm-dd"' 3:"hh:mm:ss"' 4:"yyyy年mm月dd日"' 5:"yyyymmdd"' 6:"yyyymmddhhmmss"' 7:"yy-mm-dd"' 8:"yy-mm-dd hh:mm:ss"' 9:"yyyy年mm月"' 10:"mm/dd/yyyy"' ============================================ Function Format_Time(s_Time, n_Flag)Dim y, m, d, h, mi, sFormat_Time = ""If IsDate(s_Time) = False Then Exit Functiony = cstr(year(s_Time))if y = "1900" then Exit Functionm = right("0"&month(s_Time),2)d = right("0"&day(s_Time),2)h = right("0"&hour(s_Time),2)mi = right("0"&minute(s_Time),2)s = right("0"&second(s_Time),2)Select Case n_FlagCase 1Format_Time = y & "-" & m & "-" & d & " " & h & ":" & mi & ":" & sCase 2Format_Time = y & "-" & m & "-" & dCase 3Format_Time = h & ":" & mi & ":" & sCase 4Format_Time = y & "年" & m & "月" & d & "日"Case 5Format_Time = y & m & dcase 6Format_Time= y & m & d & h & mi & scase 7Format_Time= right(y,2) & "-" & m & "-" & dcase 8Format_Time= right(y,2) & "-" & m & "-" & d & " " & h & ":" & mi & ":" & s Case 9Format_Time = y & "年" & m & "月"Case 10Format_Time = m & "/" & d & "/" & y & "/"End SelectEnd Function5:asp小写数字转大写function int2chn(n)dim i,j,k,strlen,retval,x,y,z,strz=array("零","壹","贰","叁","肆","伍","陆","柒","捌","玖")y=array("","拾","佰","仟")x=Array("","万","亿","万万亿")strlen=len(n)str1=nfor i= 1 to strlenj=mid(str1,i,1)retval=retval&z(j)if j>0 then retval=retval&y((strlen-i) mod 4)'如果大于零,加入十进位字符retval=replace(retval,z(0)&z(0),z(0))'出现两个零只留一个if ((strlen-i) mod 4)=0 and right(retval,1)=z(0) then retval=left(retval,len(retval)-1)'每四位加入进阶if ((strlen-i) mod 4)=0 then retval=retval&x(int((strlen-i)/4))'把最后的零去掉nextint2chn=retvalend function6:asp小写金额转大写Function UMoney(money)Dim lnP,Pr c,Tmp,NoB,Dx,Xx,ZhenDim China : China = "分角元拾佰仟万拾佰仟亿"Dim str: str = Array("零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖")Zhen = Truemoney = FormatNumber(money, 2)Pr c = CStr(money)Pr c = Replace(Pr c, ",", "")lnP = Len(Pr c)For i = lnP - 1 To 1 Step -1If Mid(Pr c, i, 1) = "." ThenSelect Case lnP - iCase 1Pr c = Replace(Pr c, ".", "") + "0"Case 2Pr c = Replace(Pr c, ".", "")End SelectZhen = FalseExit ForEnd IfNextIf Zhen Then Pr c = Pr c + "00"lnP = Len(Pr c)For i = 1 To lnPTmp = str(Mid(Pr c, i, 1)) & TmpNextUMoney = ""fy = 1For i = 1 To lnPXx = Mid(Tmp, i, 1)Dx = Mid(China, i, 1)If Xx <> "零" ThenUMoney = Xx & Dx & UMoneyf = 1ElseIf i = 3 ThenUMoney = Dx & UMoneyEnd IfIf i = 7 ThenUMoney = Dx & UMoneyEnd IfIf f ThenUMoney = "零" & UMoneyEnd Iff = 0End IfNextIf Zhen Then UMoney = UMoney + "整"UMoney = Replace(UMoney, "零万", "万")UMoney = Replace(UMoney, "零元", "元")End Function7:asp随机选取5组彩票Function rndtest(m_count,r_count) ''参数m_count号码总数,r_count为要取出的号码数dim x,st,ii=1st=""do while i<=r_countrandomizex=int(rnd*m_count)+1''产生1~m_count的随机数if i=r_count thenif not instr(st,x)>0thenst=st&xi=i+1end ifelseif not instr(st,x)>0thenst=st&x&","''用,分割i=i+1end ifend ifif i>=m_count thenexit do''如果m_count小于r_count将出现死循环,于是判断并跳出循环end iflooprndtest=stend functionfunction sort(ary)'冒泡函数ck=truedo Until ck = falseck=falseFor f = 0to UBound(ary) -1if clng(ary(f))>clng(ary(f+1)) thenv1=clng(ary(f))v2=clng(ary(f+1))ary(f)=v2ary(f+1)=v1ck=trueend ifnextloopsort=aryend functionfor i=0to4Mycount=rndtest(33,7)MyArray=split(Mycount,",")newArray=sort(MyArray)for i2=0to UBound(newArray)Response.Write(newArray(i2)&" ")nextResponse.Write("<br>")next8:asp对非法字符进行过滤'此文件可以对整站提交文字进行过滤'编写者:逸风'编写日期:2008-6-4'函数说明:对非法字符进行过滤'这个函数将过滤所有非中文字符function ClearString(str)dim re,str1,str2,iset re = new regexp re.Pattern = "^[\u4e00-\u9fa5\s\n\r\t]+$"for i=1to len(str)str1 = mid(str,i,1)clearString = re.Test(str1)if clearString=true thenstr2 = str2&str1end ifnextstr=str2ClearString = strend functionfunction KillKey(str)KillKey=strend function'编写者:逸风'编写日期:2008-6-4'函数说明:对非法字符进行过滤'这个函数将过滤所有非中文字符function SearchKey(str)Key="这里是非法字符嘎嘎`~~酷代码也屏蔽的"KeyArray=split(Key,",")K=ubound(KeyArray)str2=ClearString(str)for i=0to Kif Instr(str2,KeyArray(i)) thenresponse.Write("<font color=red>您所提交的信息中包含非法字符,请您返回后仔细检查所填写的内容然后再次提交您的信息!</font><a href='javascript:history.go(-1);'>返回</ a><br/><font color=#0000FF>感谢您的支持!</font><br/>非法字符:"& KeyArray(i))response.End()end ifnextSearchKey=strend functionfunction urldecode(encodestr) 'encodestr就是要解码的字符串Dim newstr,havechar,lastchar,i,char_c,next_1_c,next_1_Numnewstr=""havechar=falselastchar=""for i=1to len(encodestr)char_c=mid(encodestr,i,1)if char_c="+"thennewstr=newstr & " "elseif char_c="%"thennext_1_c=mid(encodestr,i+1,2)next_1_num=cint("&H"& next_1_c)if havechar thenhavechar=falsenewstr=newstr & chr(cint("&H"& lastchar & next_1_c))elseif abs(next_1_num)<=127thennewstr=newstr & chr(next_1_num)elsehavechar=truelastchar=next_1_cend ifend ifi=i+2elsenewstr=newstr & char_cend ifnexturldecode=newstrend functionTempStr1=urldecode(request.QueryString)TempStr2=urldecode(request.Form)'查询提交的信息如有非法字符直接终止程序运行SearchKey(TempStr1)SearchKey(TempStr2)。

asp中十分有用的17个样例代码

asp中十分有用的17个样例代码
strBrowser=Request.ServerVariables("HTTP_USER_AGENT")
If Instr(strBrowser,"MSIE") < > 0 Then
Response.redirect("ForMSIEOnly.htm")
Else
Response.redirect("ForAll.htm")
Html2Text=""
Exit Function
End If
Str1=Replace(Str1,"&lt;","<")
Str1=Replace(Str1,"&gt;",">")
Str1=Replace(Str1,"<br>",VBcrlf)
Str1=Replace(Str1,"&quot;",chr(34))
答:只有web目录设置为web application, global.asa才有效,并且一个web application的根目录下 global.asa才有效。IIS4可以使用Internet Service Manager设置application setting 怎样才能使得htm文件如同asp文件一样可以执行脚本代码?
%>
写到数据库的内容,读出来时没有了空格和换行 ,该怎么解决?
或与此类似问题
问题的解答就是在写入数据库做Replace替换
拿出我用的一个函数供大家参考 <% '----------Html转换为文本:编辑时拿来做转换

asp代码大全:ASP必须知道的精华代码大全

asp代码大全:ASP必须知道的精华代码大全
定义数据库连接些常量constadopenforwardonly游标只向前浏览记录不支持分页recordbookmarkconstadopenkey键集游标其他用户对记录说做修改将反映到记录集中但其他用户增加或删除记录不会反映到记录集中支持分页recordbookmarkconstadopendynamic动态游标功能最强但耗资源也最多用户对记录说做修改增加或删除记录都将反映到记录集中支持全功能浏览access不支持constadopenstatic静态游标只是数据个快照用户对记录说做修改增加或删除记录都不会反映到记录集中支持向前或向后移动constadlockreadonly锁定类型默认只读不能作任何修改constadlockpessimistic当编辑时立即锁定记录最安全方式constadlockoptimistic只有在update思路方法时才锁定记录集而在此前其他操作仍可对当前记录进行更改插入和删除等constadlockbatchoptimistic当编辑时记录不会被锁定而更改插入和删除是在批处理方式下完成constadcmdtexth0001constadcmdtable18
asp代码大全:ASP必须知道的精华代码大全
疯狂代码 / ĵ:http://Asp/Article15994.html 1. _disibledevent=><table border _disibledevent=>2. <body _disibledevent=>3. _disibledevent=>4. _disibledevent=>5. <link rel=\"Shortcut Icon\" document.referrer 16. 最小化、最大化、关闭窗口 <object id=hh1 id=\"clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11\"> <param name=\"Command\" value=\"Minimize\"></object> <object id=hh2 id=\"clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11\"> <param name=\"Command\" value=\"Maximize\"></object>[Page] <OBJECT id=hh3 id=\"clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11\"> <PARAM NAME=\"Command\" value=\"Close\"></OBJECT> <input type=button value=最小化 _disibledevent=><input type=button value=最大化 _disibledevent=><input type=button value=关闭 _disibledevent=>本例适用于IE 17. <% 定义数据库连接些常量 Const adOpenForwardOnly = 0 游标只向前浏览记录不支持分页、Record、BookMark Const adOpenKey = 1 键集游标其他用户对记录说做修改将反映到记录集中但其他用户增加或删除记录不会 反映到记录集中支持分页、Record、BookMark Const adOpenDynamic = 2 动态游标功能最强但耗资源也最多用户对记录说做修改增加或删除记录都将反映 到记录集中支持全功能浏览(ACCESS不支持) Const adOpenStatic = 3 静态游标只是数据个快照用户对记录说做修改增加或删除记录都不会反映到记录集 中支持向前或向后移动 Const adLockReadOnly = 1 锁定类型默认只读不能作任何修改 Const adLockPessimistic = 2 当编辑时立即锁定记录最安全方式 Const adLockOptimistic = 3 只有在Update思路方法时才锁定记录集而在此前其他操作仍可对当前记录进行 更改、插入和删除等 Const adLockBatchOptimistic = 4 当编辑时记录不会被锁定而更改、插入和删除是在批处理方式下完成 Const adCmdText = &H <script language=\"javascript\"><!-function checkNum(str){ str.match(/\\D/)null} alert(checkNum(\"1232142141\")) alert(checkNum(\"123214214a1\"))

asp常用代码大全

asp常用代码大全

asp常用代码大全x1、ASP开始结束符语法:< % %> 文件后缀.asp2、判断语句:判断表单传来的用户名和密码是否正确,并提示If request("username")="admin" thenResponse.write"恭喜,你已经登录成功"ElseResponse.write"对不起,您输入的用户名错误,请返回重输入"End ifIf request("name")="admin" and request("pass")="admin"thenResponse.redirect"admin.asp"ElseResponse.redirect"login.asp"End if3、循环语句:循环显示6条数据库中的记录写法1:for n=1 to 6response.write rs("title")&"< br>"if not rs.eof thenexit forelsers.movenextend ifnext写法二:do while not rs.eofresponse.write rs("title")&"< br>"rs.movenextloop4、常用变量转换函数:Now() 函数返回系统时间Date() 函数返回当前系统日期.CStr(int) 函数转化一个表达式为字符串CInt(string) 将一个表达式转化为数字类型Trim(request("username")) 函数去掉字符串左右的空格Left(rs("title"),10) 函数返回字符串左边第length个字符以前的字符(含第length个字符),一般在限制新闻标题的显示长度的时候用Len(string) 函数返回字符串的长度.5、Access数据库连接代码方法一:db="mydata.mdb" ‘如果放在目录中,就要写明"database/mydata.mdb"Set conn = Server.CreateObject("ADODB.Connection")connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(db)conn.Open connstr方法二:'如果你的服务器采用较老版本Access驱动,请用下面连接方法db="mydata.mdb" ‘如果放在目录中,就要写明"database/mydata.mdb"Set conn = Server.CreateObject("ADODB.Connection")connstr="driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.MapPath(db)conn.Open connstr6、Recordset对象操作数据库语法(1)打开sql语句指定的表中的数据,把这批数据放入rs对象中取出news表中所有的数据放到rs中Set Rs=Server.CreateObject("ADODB.RecordSet")SqlStr="select * from news"Rs.Open SqlStr,conn,1,1取出news表中前6条数据放到rs中Set Rs=Server.CreateObject("ADODB.RecordSet")SqlStr="select top 6 * from news"Rs.Open SqlStr,conn,1,1(2)循环显示6条rs对象中存在的数据,列表显示不带连接的写法for n=1 to 6response.write rs("title")&"< br>"if not rs.eof thenexit forelsers.movenextend ifnext带连接的写法for n=1 to 6response.write "< a href=show.asp?id=rs("id")>"& left(rs("title"),20)&"< /a>< br>"if not rs.eof thenexit forelsers.movenextend ifnext(3)向数据库添加一条数据代码Set Rs=Server.CreateObject("ADODB.RecordSet")SqlStr="select * from news"Rs.Open SqlStr,conn,1,3 ‘注意这里的1,3代表可以写入的打开数据表Rs.addnewRs("title")=trim(request("title"))Rs("neirong")=request("neirong")Rs("date")=now()rs.update ‘真正写入数据库(4)修改一条记录的代码,通过(2)中的连接传递过来了id数值Set Rs=Server.CreateObject("ADODB.RecordSet")SqlStr="select * from news where id="&request("id")Rs.Open SqlStr,conn,1,3 ‘注意这里的1,3代表可以写入的打开数据表Rs("title")=trim(request("title"))Rs("neirong")=request("neirong")Rs("date")=now()rs.update ‘真正写入数据库(5)删除数据库中一条记录,通过连接传递过来了数据得id数值Set Rs=Server.CreateObject("ADODB.RecordSet")SqlStr="select * from news where id="&request("id")Rs.Open SqlStr,conn,1,3 ‘注意这里的1,3代表可以写入的打开数据表rs.delete ‘删除该条数据7、标准Sql语句写法包括取全部记录Set Rs=Server.CreateObject("ADODB.RecordSet")SqlStr="select * from news"Rs.Open SqlStr,conn,1,1 ‘运行sql语句,把数据提出到rs对象中选取几条数据Set Rs=Server.CreateObject("ADODB.RecordSet")SqlStr="select top 6 * from news"Rs.Open SqlStr,conn,1,1 ‘运行sql语句,把6条数据提出到rs 对象中选取一条指定表中id字段数值的数据Set Rs=Server.CreateObject("ADODB.RecordSet")SqlStr="select * from news where id="&request("id")Rs.Open SqlStr,conn,1,1 ‘运行sql语句,把6条数据提出到rs 对象中添加一条表单传过来的数据替换Set Rs=Server.CreateObject("ADODB.RecordSet")SqlStr="insert into news(title,neirong) values(request("title"), request("neirong"))修改一条指定表中id字段数值的数据,用表单传过来的数据替换Set Rs=Server.CreateObject("ADODB.RecordSet")SqlStr="update news set title=’"&request("title")&"’,neirong=’"&request("内容")&"’ where id="&request("id")Rs.Open SqlStr,conn,1,3 ‘运行sql语句,把数据提出到rs对象中删除一条指定表中id字段数值的数据Set Rs=Server.CreateObject("ADODB.RecordSet")SqlStr="delete from news where id="&request("id")Rs.Open SqlStr,conn,1,3 ‘运行sql语句,把数据提出到rs对象中8、当点击按钮时候表单带着的数据传送到哪个文件,在哪里指定?< form method="post" action="addsave.asp">< input type="text" name="title">< input type="text" name="neirong">< input type="submit" name="Submit" value="提交">< /form>9、表单提交来的数据接收并显示到屏幕上的代码response.write request("name")response.write now()response.write trim(request("name"))10、利用Application对象作计数器的语法在网页的头部加入Application.LockApplication("counter") = Application("counter") + 1Application.UnLock在需要显示计数内容的网页的地方,加入下面的语句response.write Application("counter")11、利用Session对象保护后台管理页面admin.asp,防止未登陆用户进入在网站后台网页admin.asp的头部加入下面的代码,if session(admin)< >"ok" thenresponse.redirect"login.asp"response.endend if在网站后台登陆页的密码验证部分标准写法AdmName=Request.Form("Name")AdmPass=Request.Form("Pass")Set Rs=Server.CreateObject("ADODB.RecordSet")SqlStr="Select * from Admin where name='"&AdmName&"' and pass='"&AdmPass&"'"Rs.Open SqlStr,conn,1,3if Rs.EOF AND RS.BOF thenResponse.Redirect("login.asp")response.endelsesession("admin")="ok"Response.Redirect("admin.asp")response.endend if12、分页代码sql = "select……………………省略了sql语句Set rs=Server.Createobject("ADODB.RECORDSET")rs.Open sql, conn, 1, 1if not rs.eof thenpages = 30 '定义每页显示的记录数rs.pageSize = pages '定义每页显示的记录数allPages = rs.pageCount '计算一共能分多少页page = Request.QueryString("page")'通过浏览器传递的页数’if语句属于基本的排错处理if isEmpty(page) or Cint(page) < 1 thenpage = 1elseif Cint(page) > allPages thenpage = allPagesend ifrs.AbsolutePage = pageDo while not rs.eof and pages > 0'这里输出你要的内容………………pages = pages - 1rs.MoveNextLoopelseResponse.Write("数据库暂无内容!")End ifrs.CloseSet rs = Nothing分页页码连接和跳转页码程序< form Action="v3.asp" Method="GET">< %If Page < > 1 ThenResponse.Write "< A HREF=?Page=1>第一页< /A>"Response.Write "< A HREF=?Page=" & (Page-1) & ">上一页< /A>"End IfIf Page < > rs.PageCount ThenResponse.Write "< A HREF=?Page=" & (Page+1) & ">下一页< /A>"Response.Write "< A HREF=?Page=" & rs.PageCount & ">最后一页< /A>"End If%>< p>输入页数:< input TYPE="TEXT" Name="Page" SIZE="3"> 页数:< font COLOR="Red">< %=Page%>/< %=rs.PageCount%>< /font> < /p>< /form>13、分行列显示图片和产品名称的代码(4列x3行=12个)< %Set Rs=Server.CreateObject("ADODB.RecordSet")SqlStr="select top 12 * from myproduct"Rs.Open SqlStr,conn,1,1i=1%>< table width="90%" border="1" cellspacing="0" sellpadding="0">< tr>< %do while not rs.eof%>< td align="center">< img src="< %=rs("imgurl")%>" width="52" height="120">< br>< %=rs("productname")%>< /td>< % if i mod 4=0 then response.write"< /tr>< tr>"i=i+1rs.movenextlooprs.close%>< /tr>< /table>14、ASP数据库连接之ACCESS-SQLSERVER< %IsSqlData=0 定义数据库类别,0为Access数据库,1为SQL 数据库If IsSqlData=0 ThenAccess数据库datapath ="data/" 数据库目录的相对路径datafile ="data.mdb" 数据库的文件名connstr="Provider=Microsoft.Jet.OLEDB.4.0;DataSource="&Server.MapPath(""&datapath&""&datafile&"") Connstr="DBQ="&server.mappath(""&datapath&""&datafil e&"")&";DRIVER={Microsoft Access Driver (*.mdb)};"ElseSQL数据库SqlLocalName ="(local)" 连接IP [ 本地用 (local) 外地用IP ] SqlUsername ="sa" 用户名SqlPassword ="1" 用户密码SqlDatabaseName="data" 数据库名ConnStr = "Provider=Sqloledb;User ID=" & SqlUsername & "; Password=" & SqlPassword & "; Initial Catalog = " & SqlDatabaseName & "; Data Source=" & SqlLocalName & ";"END IFOn Error Resume NextSet conn=Server.CreateObject("ADODB.Connection")conn.open ConnStrIf Err Thenerr.ClearSet Conn = NothingResponse.Write "数据库连接出错,请检查连接字串。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
}
cc("12/23/2002",2)
</script>
24. 选择了哪一个Radio
<HTML><script language="vbscript">
function checkme()
for each ob in radio1
if ob.checked then window.alert ob.value
var r =e.createTextRange();
r.moveStart('character',e.value.length);
r.collapse(true);
r.select();
}
</script>
<input type=text name=text1 value="123" onfocus="cc()">
Const adCmdTable = &H0002
%>
18. 网页不会被缓存
HTM网页
<META HTTP-EQUIV="pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
// --></script>
20. 获得一个窗口的大小
document.body.clientWidth,document.body.clientHeight
21. 怎么判断是否是字符
if (/[^\x00-\xff]/g.test(s)) alert("含有汉字");
else alert("全是字符");
function cc(dd,dadd)
{
//可以加上错误处理
var a = new Date(dd)
a = a.valueOf()
a = a - dadd * 24 * 60 * 60 * 1000
a = new Date(a)
alert(a.getFullYear() + "年" + (a.getMonth() + 1) + "月" + a.getDate() + "日")
<META HTTP-EQUIV="expires" CONTENT="Wed, 26 Feb 1997 08:21:57 GMT">
或者<META HTTP-EQUIV="expires" CONTENT="0">
ASP网页
Response.Expires = -1
Response.ExpiresAbsolute = Now() - 1
6. <link rel="Bookmark" href="favicon.ico"> 可以在收藏夹中显示出你的图标
7. <input style="ime-mode:disabled"> 关闭输入法
8. 永远都会带着框架
<script language="javascript"><!--
Response.cachecontrol = "no-cache"
PHP网页
header("Expires: Mon, 26 Jul 1997 05:0("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
Const adOpenStatic = 3 '静态游标,只是数据的一个快照,用户对记录说做的修改,增加或删除记录都不会反映到记录集中。支持向前或向后移动
Const adLockReadOnly = 1 '锁定类型,默认的,只读,不能作任何修改
Const adLockPessimistic = 2 '当编辑时立即锁定记录,最安全的方式
// --></SCRIPT>
10. <noscript><iframe src=*.html></iframe></noscript> 网页将不能被另存为
11. <input type=button value=查看网页源代码
onclick="window.location = 'view-source:'+ '/'">
19. 检查一段字符串是否全由数字组成
<script language="javascript"><!--
function checkNum(str){return str.match(/\D/)==null}
alert(checkNum("1232142141"))
alert(checkNum("123214214a1"))
end if
%>
13. 取得控件的绝对位置
//javascript
<script language="javascript">
function getIE(e){
var t=e.offsetTop;
var l=e.offsetLeft;
while(e=e.offsetParent){
Const adLockOptimistic = 3 '只有在调用Update方法时才锁定记录集,而在此前的其他操作仍可对当前记录进行更改、插入和删除等
Const adLockBatchOptimistic = 4 '当编辑时记录不会被锁定,而更改、插入和删除是在批处理方式下完成的
Const adCmdText = &H0001
<INPUT type="button" value="check" onclick="checkme()">
</BODY></HTML>
25.获得本页url的request.servervariables("")集合
Response.Write "<TABLE border=1><!-- Table Header --><TR><TD><B>Variables</B></TD><TD><B>value</B></TD></TR>"
<OBJECT id=hh3 classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11">
<PARAM NAME="Command" value="Close"></OBJECT>
<input type=button value=最小化 onclick=hh1.Click()>
1. oncontextmenu="window.event.returnvalue=false" 将彻底屏蔽鼠标右键
<table border oncontextmenu=return(false)><td>no</table> 可用于Table
2. <body onselectstart="return false"> 取消选取、防止复制
12. 怎样通过asp的手段来检查来访者是否用了代理
<% if Request.ServerVariables("HTTP_X_FORWARDED_FOR")<>"" then
response.write "<font color=#FF0000>您通过了代理服务器,"& _
"真实的IP为"&Request.ServerVariables("HTTP_X_FORWARDED_FOR")
15. 判断上一页的来源
asp:
request.servervariables("HTTP_REFERER")
javascript:
document.referrer
16. 最小化、最大化、关闭窗口
<object id=hh1 classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">
next
end function
</script><BODY>
<INPUT name="radio1" type="radio" value="style" checked>Style
相关文档
最新文档