记录的一些ASP学习笔记(2)

2008-02-23 09:34:25来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折



%>

###########################################################################
判断表单是否填写完整
1、If name = "" Or email = "" Or subject = "" Or _
textmemo = "" Then
Response.Write "<script>alert('松子说了,不填完就别想留言!');history.go(-1);</script>"
Response.End
End If

增加新数据方法
1、rs.open ""&s&"",con,1,3
rs.addnew
rs("name")=request("name")
rs("depa")=request("depa")
rs.update
%>

##############################################################

常用函数
一、字符类
1、Asc(string)'该数值为参数字符串第一个字母的ASCII值如Asc(a)=97
2、Chr(charcode)'将指定的字符码转为字符(string) 如chr(97)等于A
3、Len(string)'计算参数中字符串的字符数目如 len(ab c)=4
4、Left(字符串,指定长度) 如left("123 4",3)=123
5、Right 同上
6、MId(字符串,开始字符,指定长度)如mid("123 4",3,1)=1
7、LTrim(字符串)'去除字串中的前置空白如Ltrim(" hello“)="hello"
8、RTrim(字符串)同上
9、Trim(字符串)'去除字符串前、后的空白
10、UCase(字符串)将字符串中所有字符转换为大写字符如Ucase("h")="H"
11、Lcase(字符串)同上
12、Space(空格数目) 如"hello"&space(1)&"jacky"=hello jacky
13、String(字符数,字符)用来产生一个重复字符组成的字符串如string(3,"ab")=aaa'两个以上字符时只重复第一个
14、Join(来源数组[,分隔字符])
15、Split (来源字符串,分隔字符串)
16、replace(源字符串,源字符串中的字符,要变成的字符串)
如 a="long" response.write (replace(a,"l","s"))=song
二、数学类
1、Abs(数值)'返回参数值的绝对值,返回值的类型与参数数值类型相同。
2、Sgn(数值)判断参数数值的正负号,参数为正数时返回1,负数返回-1,0返回0
3、Sqr(数值)求得数值的平方根,不可为负
4、Hex(数值) 转化为16进位
5、Oct (数值) 转化为8进位
三、类别转换
1、Int(数值) 返回数值的整数部分 如int(3,3)=3
2、Fix(数值)同上,只是int(-3.8)=4 而fix(-3.8)=3
3、Str(数值) 将数值转换为字符串。
4、Format(处理对象[,格式])
5、Year(date)/Month(date)/Day(date)取得年、月、日
6、Hour(time)/Minute(time)/Second(time)
7、WeekdayName(1-7)如weekdayname(1)=星期日
8、MonthName(1-12)如monthname(1)=一月
四、比较运算符:= 、<>、<、>、<=、>=
五、Not逻辑运算符:And 、Or、Not
六、指定运算符号:=
七、运算符符号: 、*、/、\(整数除法)2\5=0、Mod(除法取余数)、^乘(次方)5^2=25
八、串拉运算符:& 如abc&efg=abcdefg

从表中删除一条记录:
1、<a href=del.asp?ID=<%=RS("id")%> onclick="return confirm('你真的要删除吗?')">删除</a>
2、<%
id=request("id")
Set CN = Server.CreateObject("ADODB.Connection")
CN.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ="&Server.MapPath("new.mdb")
Set RS=Server.CreateObject("ADODB.Recordset")
RS.Open "new",CN,1,3
SQL="delete * From new where id="&id
cn.execute sql
response.redirect("index.asp")
%>

###########################################################################
保持文本框格式一致的问题:
<%
function th(str)
str=replace(str,"妈的","MD")
str=replace(str,"靠","KAO")
th=str
end function

function encode(str)
str = replace(str, ">", "&gt;")
str = replace(str, "<", "&lt;")
str = Replace(str, CHR(32), "&nbsp;")
str = Replace(str, CHR(13), "")
str = Replace(str, CHR(10) & CHR(10), "</P><P>")
str = Replace(str, CHR(10), "<BR>")
encode=str
end function
%>

<%title=request.form("title")
content=request.form("content")%>

文章标题:<%=th(title)%><hr>
文章内容:<%=encode(th(content))%>


###########################################################################
技巧:
1、response.write chr(10)'输出一个换行符号
2、本页的文件名<%=request.servervariables("path_info")%>
3、with response
<%
with response
.write "this"
.write "is"
.write "a"
.write "test"
end with
%>

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:利用ASP程序实现将远程页面的所有内容下载到本地

下一篇:ASP实现备份sql server数据