电脑爱好者,提供IT资讯信息及各类编程知识文章介绍,欢迎大家来本站学习电脑知识。 最近更新 | 联系我们 RSS订阅本站最新文章
电脑爱好者
站内搜索: 
当前位置:首页>> Asp>>asp编程开发常用的程序代码之二:

asp编程开发常用的程序代码之二

来源:www.cncfan.com | 2006-8-9 | (有2510人读过)

清除缓存,重新加载页面
<%response.expires = 0
response.expiresabsolute = now() - 1
response.addheader "pragma","no-cache"
response.addheader "cache-control","private"
response.cachecontrol = "no-cache"
%>


检索并删除数据库里的重复记录
conn.execute("delete from table where id not in (select distinct from table)")

文件删除函数 <%
’文件删除函数
function deletefile(filename)
if filename<>"" then
set fso=server.createobject("scripting.filesystemobject")
if fso.fileexists(filename) then
fso.deletefile filename
else
response.write "<script>alert(’该文件不存在’);</script>"
end if
end if
end function

strfile=server.mappath("filename")
deletefile(strfile)
%>

asp字数计算函数 <%
function wordcount(strinput)
dim strtemp
strtemp = replace(strinput, vbtab, " ")
strtemp = replace(strtemp, vbcr, " ")
strtemp = replace(strtemp, vblf, " ")

’ 删除字首字尾空格
strtemp = trim(strtemp)

’ 替换为一个空格
do while instr(1, strtemp, " ", 1) <> 0
strtemp = replace(strtemp, " ", " ")
loop
wordcount = ubound(split(strtemp, " ", -1, 1)) +1
end function
%>
全正则的检测ip是否合法的函数 function checkip2(sipaddress)
{
var exp=/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
var reg = sipaddress.match(exp);
var errmsg="你输入的是一个非法的ip地址段!\nip段为::xxx.xxx.xxx.xxx(xxx为0-255)!"
var msg="你输入的是一个合法的ip地址段!"
if(reg==null)
{
alert(errmsg);
}
else
{
alert(reg);
}
}


关闭子窗口时刷新父窗口 在子窗口
<script language="javascript">
window.opener.location="父窗口页面"
window.close()
</script>


文本框输入限制:
<script>
function reginput(obj, reg, inputstr)
{
var docsel = document.selection.createrange()
if (docsel.parentelement().tagname != "input") return false
osel = docsel.duplicate()
osel.text = ""
var srcrange = obj.createtextrange()
osel.setendpoint("starttostart", srcrange)
var str = osel.text + inputstr + srcrange.text.substr(osel.text.length)
return reg.test(str)
}
</script>

小写英文:<xmp style= "display:inline"> </xmp>
<input onkeypress = "return reginput(this, /^[a-z]*$/, string.fromcharcode(event.keycode))"
onpaste = "return reginput(this, /^[a-z]*$/, window.clipboarddata.getdata(’text’))"
ondrop = "return reginput(this, /^[a-z]*$/, event.datatransfer.getdata(’text’))"
style="ime-mode:disabled"
><br>

大写英文:<xmp style= "display:inline"> </xmp>
<input onkeypress = "return reginput(this, /^[a-z]*$/, string.fromcharcode(event.keycode))"
onpaste = "return reginput(this, /^[a-z]*$/, window.clipboarddata.getdata(’text’))"
ondrop = "return reginput(this, /^[a-z]*$/, event.datatransfer.getdata(’text’))"
style="ime-mode:disabled">
<br>

任意数字:<xmp style="display:inline"> </xmp>
<input onkeypress = "return reginput(this, /^[0-9]*$/, string.fromcharcode(event.keycode))"
onpaste = "return reginput(this, /^[0-9]*$/, window.clipboarddata.getdata(’text’))"
ondrop = "return reginput(this, /^[0-9]*$/, event.datatransfer.getdata(’text’))"
style="ime-mode:disabled"
><br>

限2位小数:<xmp style="display:inline"> </xmp>
<input onkeypress = "return reginput(this, /^\d*\.@\d{0,2}$/, string.fromcharcode(event.keycode))"
onpaste = "return reginput(this, /^\d*\.@\d{0,2}$/, window.clipboarddata.getdata(’text’))"
ondrop = "return reginput(this, /^\d*\.@\d{0,2}$/, event.datatransfer.getdata(’text’))"
style="ime-mode:disabled"
> 如: 123.12<br>


日  期:<xmp style="display:inline"> </xmp>
<input onkeypress = "return reginput(this, /^\d{1,4}([-\/](\d{1,2}([-\/](\d{1,2})@)@)@)@$/, string.fromcharcode(event.keycode))"
onpaste = "return reginput(this, /^\d{1,4}([-\/](\d{1,2}([-\/](\d{1,2})@)@)@)@$/, window.clipboarddata.getdata(’text’))"
ondrop = "return reginput(this, /^\d{1,4}([-\/](\d{1,2}([-\/](\d{1,2})@)@)@)@$/, event.datatransfer.getdata(’text’))"
style="ime-mode:disabled"
> 如: 2002-9-29<br>

任意中文:<xmp style="display:inline"> </xmp>
<input onkeypress = "return reginput(this, /^$/, string.fromcharcode(event.keycode))"
onpaste = "return reginput(this, /^[\u4e00-\u9fa5]*$/, window.clipboarddata.getdata(’text’))"
ondrop = "return reginput(this, /^[\u4e00-\u9fa5]*$/, event.datatransfer.getdata(’text’))"
><br>

部分英文:<xmp style="display:inline"> </xmp>
<input onkeypress = "return reginput(this, /^[a-e]*$/, string.fromcharcode(event.keycode))"
onpaste = "return reginput(this, /^[a-e]*$/, window.clipboarddata.getdata(’text’))"
ondrop = "return reginput(this, /^[a-e]*$/, event.datatransfer.getdata(’text’))"
style="ime-mode:disabled"
> 范围: a,b,c,d,e<br>

部分中文:<xmp style="display:inline"> </xmp>

<script language=javascript>
function checkchinese(oldlength, obj)
{
var otr = window.document.selection.createrange()
var reg = /[^一二三四五六七八九十]/g
otr.movestart("character", -1*(obj.value.length-oldlength))
otr.text = otr.text.replace(reg, "")
}
</script>
<input onkeypress="return false" onkeydown="settimeout(’checkchinese(’+this.value.length+’,’+this.uniqueid+’)’, 1)"
onpaste = "return reginput(this, /^[一二三四五六七八九十]*$/, window.clipboarddata.getdata(’text’))"
ondrop = "return reginput(this, /^[一二三四五六七八九十]*$/, event.datatransfer.getdata(’text’))"
> 范围: 一二三四五六七八九十<br>

[ctrl+a 全选 ctrl+c 复制]

不能点右键,不用ctrl+a,不能复制作!
<body oncontextmenu="window.event.returnvalue=false"
onkeypress="window.event.returnvalue=false"
onkeydown="window.event.returnvalue=false"
onkeyup="window.event.returnvalue=false"
ondragstart="window.event.returnvalue=false"
onselectstart="event.returnvalue=false">
</body>

Asp热门文章排行
网站赞助商
购买此位置

 

关于我们 | 网站地图 | 文档一览 | 友情链接| 联系我们

Copyright © 2003-2024 电脑爱好者 版权所有 备案号:鲁ICP备09059398号