技巧
1. 幾個常用函數
Round(pi, 2) 四捨五入
FormatNumber(k,4) ' 把 k 格式化為帶四位小數點的數。
eg. 如果k =20000則顯示為20,000.00;如果把formatnumber(k,0)則為20,000
Replace(expression,find,replacewith) '返回一字串,其中指定的子串已被另一個子串替換
Left(String,Length) '返回指定數目的從字串的左邊算起的字串。
Split(expression[, delimiter[, count[, start]]]) '返回基於 0 的一維數組,其中包含指定數目的子字串。
eg. 常用這個 Split(String,[delimiter]) ' 用delimiter(用於標識子字串界限的字元)來劃分字串
Instr(String1,String2) '返回某字串在另一字串中第一次出現的位置
eg1. if instr(addation,"密碼配置表")<>0 then '說明存在
eg2. if instr(str,”AP”) >0 不好區分str = (AP,AP&AC),此時只要變為(’AP’,’AP&AC’),再用instr(str,”’AP’”)
2. 快顯視窗Pick值
function pickupSP(spdisid,pjnum,pdcode)
{
window.opener.<%=theForm%>.RefNum<%=Spid%>.value=spdisid;
window.opener.<%=theForm%>.LineS<%=Spid%>.value=pjnum;
window.opener.<%=theForm%>.kokey<%=Spid%>.value=pdcode;
window.close();
}
3. ASP控製圖片顯示的大小(等比例縮放)
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<script language="JavaScript">
<!--
var flag=false;
function DrawImage(ImgD){
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= 164/112){
if(image.width>164){
ImgD.width=164;
ImgD.height=(image.height*164)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"x"+image.height;
}
else{
if(image.height>112){
ImgD.height=112;
ImgD.width=(image.width*112)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"x"+image.height;
}
}
}
//-->
</script>
</HEAD>
<BODY>
<a href="http://www.163design.net/a/q/img.jpg" target="_blank"><img src="http://www.163design.net/a/q/img.jpg" border="0" width="164" height="112" ></a>
</BODY>
</HTML>
4. ASP中對資料庫表的操作(INSERT/UPDATE/DELETE),可使用交易處理,並支援多交易處理.
在ASP的資料庫物件連結化物件中,提供了一下屬性:
BeginTrans 事務開始
CommitTrans 事務提交
RollbackTrans 交易回復
<%
On Error Resume Next ’錯誤發生後繼續處理
'Asp中使用事務
Set conn=Server.CreateObject("ADODB.Connection")
conn.Open "course_dsn","course_user","course_password"
conn.begintrans '開始事務
sql="delete from user_info"
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,3,3
if conn.errors.count>0 then '有錯誤發生
conn.rollbacktrans '復原
set rs=nothing
conn.close
set conn=nothing
response.write "交易失敗,復原至修改前的狀態!"
response.end
else
conn.committrans '提交事務
set rs=nothing
conn.close
set conn=nothing
response.write "交易成功!"
response.end
end if
%>
在ASP中,不提供事務的結束,BeginTrans只作用於自己的域,類似於變數聲明一樣,如果在函數體內BeginTrans,則事物只作用於本函數體,如果BeginTrans在函數體外,處於頁面級,則事務的範圍從BeginTrans開始,到頁面的結束均處於事務的管理狀態下.
[1] [2] 下一頁