经典的asp整理 (陆续更新)

15 篇文章 0 订阅

1、关闭窗口在图片的连接上写javascript:window.close();
 提交的图片连接写javascript:document.Form1.submit();
 删除之前出现确认对话框:
 <a href="del.asp?id=<%=rs("rowid")%>" ONCLICK="javascript:return confirm('真的要删除数据吗?')">删除</a>

2、用VBScript弹出提示框然后跳转到指定页面
 <%
  Response.Write "<script language='javascript'>alert(""提交成功!"");location.href=""AddBook.asp"";</script>"
 %>


3、页面摘入等待。。。。脚本说明:
 把如下代码加入<head>区域中
 <SCRIPT LANGUAGE="JavaScript">
      document.write("<font size=6 color=blue face='楷体_GB2312'><B>正在载入细溪驿站首页,请稍等..</B></font>");
      window.clear;
      window.location.href="
http://yzty.europe.webmatrixhosting.net";
 </SCRIPT>


4、在Text直接修改记录,然后点修改保存记录
  <%count=0
   do while not (rs.eof or rs.bof) and count<rs.PageSize %>
   <form action="webGroupEdit.asp" method="post" name="GroupEdit" onSubmit="return Checkedit()">
          <tr bgcolor="E9F3FF">
            <td>&nbsp;<%=rs("id")%> <input name="b" type="hidden" id="b" value="<%=rs("id")%>">
            <input name="currpage" type="hidden" id="currpage" value="<%=page%>"></td>
            <td height="18"><input name="a" type="text" id="a" value="<%=rs("MemGroupName")%>" size="20" maxlength="50">
            </td>
            <td height="18"><input name="c" type="text" id="c" value="<%=rs("Remark")%>" size="25" maxlength="30"></td>
            <td><input type="submit" name="Submit" value=" 修改 " ></td>
            <td><div align="center"><a href="webGroupDel.asp?id=<%=rs("id")%>&page=<%=page%>" onClick="return check()">删除</a></div></td>
          </tr>
     </form>
          <%
   count=count+1
   rs.movenext
   loop
   %>

5、自动计算问题:
 <input type="hidden" name="selvalue">
 <SELECT NAME="select1" onChage="javascript:document.form1.selvalue.value=this.options[this.options.selectedIndex].text">
 <option value="1">新浪</option>
 <option value="2">百度</option>
 <option value="3">中华网</option>
 <option value="4">腾讯</option>
 </SELECT>


6.  局部打印
<style>

@media print {

.ipt {display:none}

</style>

<div class="ipt">这一行就不显示</div>

这里就可以显示


7.文章列表中常用的颜色交替
<style>
tr{background-color:expression((this.rowIndex%2==0)?"blue":"red");ryo:expression(οnmοuseοver=function(){this.style.backgroundColor=(this.style.backgroundColor!='gray'?'gray':((this.rowIndex%2==0)?"blue":"red"))},οnmοuseοut=function(){this.style.backgroundColor=(this.style.backgroundColor!='gray'?'gray':((this.rowIndex%2==0)?"blue":"red"))})}
</style>
<TABLE width="200" cellpadding="0" cellspacing="2" border="0" id="t1">
<TR><TD>1</TD></TR>
<TR><TD>1</TD></TR>
<TR><TD>1</TD></TR>
<TR><TD>1</TD></TR>
<TR><TD>1</TD></TR>
<TR><TD>1</TD></TR>
<TR><TD>1</TD></TR>
<TR><TD>1</TD></TR>
</TABLE>

==========计算页面的执行时间===========

<%
dim startime,endtime
startime=timer()
%>

    <%
dim startime,endtime
startime=timer()
%>

    最后就是在页面代码的最后面加入以下代码:

<%
endtime=timer()
response.write "页面执行时间:"&FormatNumber((endtime-startime)*1000,3)&"毫秒"
response.end
%>

<%
endtime=timer()
response.write "页面执行时间:"&FormatNumber((endtime-startime)*1000,3)&"毫秒"
response.end
%>

========取完整url的函数=========

<%
Dim temp,ServerUrl
Temp=Split(Request.servervariables("SERVER_PROTOCOL"),"/")
ServerUrl=Temp(0)& "://" & Request.ServerVariables("Server_name") & Request.ServerVariables("Script_name")
if request.ServerVariables("QUERY_STRING")<>"" then ServerUrl=ServerUrl&"?"
ServerUrl=ServerUrl&request.ServerVariables("QUERY_STRING")
response.write ServerUrl &"<br>"
%>

<%
Dim temp,ServerUrl
Temp=Split(Request.servervariables("SERVER_PROTOCOL"),"/")
ServerUrl=Temp(0)& "://" & Request.ServerVariables("Server_name") & Request.ServerVariables("Script_name")
if request.ServerVariables("QUERY_STRING")<>"" then ServerUrl=ServerUrl&"?"
ServerUrl=ServerUrl&request.ServerVariables("QUERY_STRING")
response.write ServerUrl &"
"
%>

============显示当前目录下所以的文件==========

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%=server.MapPath("/")%>
<%
'Set fso = CreateObject("Scripting.FileSystemObject")
'fso.CreateFolder ("e:/fd")
'fso.files ("e:/")
dirtowalk="web"
set fs=server.CreateObject("Scripting.FileSystemObject")
set f=fs.GetFolder(server.MapPath(dirtowalk))
set fc=f.files
for each whatever in fc
response.Write "<a href='"
response.Write whatever.name
response.Write "'>"
response.Write whatever.name&"   "&whatever.datecreated
response.Write "</a><br>"
next
%>
<%=server.MapPath("/")%>
<%
'Set fso = CreateObject("Scripting.FileSystemObject")
'fso.CreateFolder ("e:/fd")
'fso.files ("e:/")
dirtowalk="web"
set fs=server.CreateObject("Scripting.FileSystemObject")
set f=fs.GetFolder(server.MapPath(dirtowalk))
set fc=f.files
for each whatever in fc
response.Write ""
response.Write whatever.name&"?? "&whatever.datecreated
response.Write "

"
next
%>

=======计算中英文字符串的总长度=========

<%
Function CheckStringLength(txt)
     txt=trim(txt)
     x = len(txt)
     y = 0
     for ii = 1 to x
        if asc(mid(txt,ii,1)) < 0 or asc(mid(txt,ii,1)) >255 then  
 ' 如果是中文
            y = y + 2
        else
            y = y + 1
        end if
     next
     CheckStringLength = y

    End Function
response.Write(CheckStringLength("fsdfs地在在dfsdf"))
%>

从publish 表中取出第 n 条到第 m 条的记录:
SELECT TOP m-n+1 *
FROM publish
WHERE (id NOT IN
     (SELECT TOP n-1 id
     FROM publish))

id 为publish 表的关键字


 

取出完整的URL

<%
Dim temp,ServerUrl
Temp=Split(Request.servervariables("SERVER_PROTOCOL"),"/")
ServerUrl=Temp(0)& "://" & Request.ServerVariables("Server_name") & Request.ServerVariables("Script_name")
if request.ServerVariables("QUERY_STRING")<>"" then ServerUrl=ServerUrl&"?"
ServerUrl=ServerUrl&request.ServerVariables("QUERY_STRING")
response.write ServerUrl &"<br>"
%>


 


 


 

Function CheckStr(Str)
 If Trim(Str)="" Or IsNull(str) Then Exit Function
 Checkstr=Replace(Trim(Str),"'","''")
End Function

Function HtmlEncode(str)
    If Trim(Str)="" Or IsNull(str) Then Exit Function
    str=Replace(str,">","&gt;")
    str=Replace(str,"<","&lt;")
    str=Replace(str,Chr(32),"&nbsp;")
    str=Replace(str,Chr(9),"&nbsp;")
    str=Replace(str,Chr(34),"&quot;")
    str=Replace(str,Chr(39),"&#39;")
    str=Replace(str,Chr(13),"")
    str=Replace(str,Chr(10) & Chr(10), "</p><p>")
    str=Replace(str,Chr(10),"<br> ")
    HtmlEncode=str
End Function

Function ShowEncode(str)
    If Trim(Str)="" Or IsNull(str) Then Exit Function
    str=Replace(str,"&gt;",">")
    str=Replace(str,"&lt;","<")
    str=Replace(str,"&nbsp;",Chr(32))
    str=Replace(str,"&nbsp;",Chr(9))
    str=Replace(str,"&quot;",Chr(34))
    str=Replace(str,"&#39;",Chr(39))
    str=Replace(str,"",Chr(13))
    str=Replace(str, "</p><p>",Chr(10) & Chr(10))
    str=Replace(str,"<br> ",Chr(10))
    ShowEncode=str
End Function

<%
Function CheckStringLength(txt)
???? txt=trim(txt)
???? x = len(txt)
???? y = 0
???? for ii = 1 to x
??????? if asc(mid(txt,ii,1)) < 0 or asc(mid(txt,ii,1)) >255 then??
?' 如果是中文
??????????? y = y + 2
??????? else
??????????? y = y + 1
??????? end if
???? next
???? CheckStringLength = y

??? End Function
response.Write(CheckStringLength("fsdfs地在在dfsdf"))
%>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值