您的位置:首页 > 编程语言 > ASP

整理出一些运用ASP+ACCESS过程的技巧或需注意的地方。

2008-10-03 17:06 507 查看
/用js获取顶部地址栏=后面的值
var d=top.location.href.split('=').pop();
document.write (''+ d +'')

/aa="2009-5-6 18:02:41" 日期相减
datediff("h",aa,now())

/bb=DateAdd("d",1,b) 日期相加

/跳出DO WHILE
<% i=i+1
HistrolyN=HistrolyN+1
If HistrolyN >= MaxPerPage Then Exit Do
RsItem.Movenext

Loop
%>

/iframe,框架无缝镶入网页。
<iframe frameborder="0" height="100%" style="width:100%" src="test.asp"

scrolling="no"></iframe>
1. 被包含页body应用overflow:hidden 即在被包含页中应用15.如何控制横向和纵向滚动条的显

隐?
2. 被包含页的body标签加scroll="no"
3. 设置iframe scrolling="no"

/所有查询结果 赋给一个变量
do while not rsT.eof
if a="" then
a=rsT("arrChildID")&"|"
else
a=a&rsT("arrChildID")&"|"
end if
rsT.movenext
loop
Response.Write A

/细黑的文本分割线
<hr color="#000000" size="1">

/判断表单内容
function CheckForm()
{
if(document.thisForm.username.value.length<1)
{
alert("用户名称不能为空!");
document.thisForm.username.focus();
document.thisForm.username.select();
return false;
}
}

/input 图片按钮,'_self',''
<input type="image" name="submit" src="*.*" onClick="document.formname.submit()">
统一表单_self无效
onClick="window.open('reg.asp','_self','')">

/DIV校验网址:http://validator.w3.org/

/CSS校验网址:http://jigsaw.w3.org/css-validator/

/JS控制DIV自适应高度
<script>
var rightH=document.getElementById("right").scrollHeight;
var leftH=document.getElementById("left").scrollHeight;
if(rightH<leftH){
document.getElementById("right").style.height=leftH+"px";
}
</script>

/DIV 1PX 细线
overflow:hidden;font-size:1px;BORDER-right: #f0f0f0 1px solid;height:1px;

/完美清除clear div
.clear {border-top:0;margin-top:0;clear:both;visibility:hidden;}

/阴影字体
FILTER: dropshadow(color=#cccccc, offx=2, offy=2, positive=2);

/DIV的列表样式定义LI
.faq_list_li {
list-style:none;PADDING-RIGHT: 0px; PADDING-LEFT: 10px; FONT-SIZE: 13px;

PADDING-BOTTOM: 6px; MARGIN: auto; WIDTH: 550px; CURSOR: pointer; COLOR: #666;

PADDING-TOP: 15px; BORDER-BOTTOM: #f0f0f0 1px solid; TEXT-ALIGN: left
}
li{margin-left:0px;list-style:none;}
ul {margin:0; padding:0; text-align:left;}

/鼠标悬停表格变色
<tr onmouseover="this.style.backgroundColor='#DCF6FF';return true;"

onmouseout="this.style.backgroundColor='#FFF';return true;">

/自动刷新,20秒一次
<meta http-equiv="refresh" content="20">
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">

/历史返回
javascript:history.go(-1)

/1008
1024分辨率下网页宽度是1008不会出现滚动条

/根据按request字段并且都有hotel_id字段搜索2个表的所有内容。
sql="select * from hotel,room where hotel.hotel_id=room.hotel_id and

hotel.hotel_id="&request("hotel_id")&""

/根据按request字段搜索2个表的所有内容。
sql="select * from hotel,room where room.room_id="&request("room_id")&" and

hotel.hotel_id="&request("hotel_id")&""

/搜索头10条,并把表内指定类型按符合 leixing=出售的时间找出,并按 FBSJ B ID排序。
sql="select top 10 id,biaoti,leixing,a,b,fbsj from xinxi where leixing='出售' order

by fbsj desc,b desc,id desc"
rst.open sql,conn,1,1

/注意双引号
sql="select * from room where room_id="&request("room_id")

/隐藏提room_id=<%=rs("room_id")%>
<input name="room_id" type="hidden" value="<% =rs("room_id") %>">

/如果字段数据为A则输出B。
<% if rsh("hotel_star")="五星级" then %><font color="#FF0000">★★★★★</font><%

else %>内容<% end if %>

/某些网页病毒靠这条代码加载,一些变种的会通过一些转码进行伪装。
document.writeln

/在CSS设置链接字体颜色,除了link之外。visited也要一并设置.a1为样式名
A.a1:visited {FONT-SIZE: 9pt; COLOR: #CCCCCC; TEXT-DECORATION: none}

/SELECT 语言里加ONCHANGE 实现Input里加onclick效果
<SELECT onchange="imgchange()" NAME="selImage" size=1>
<% dim i for i=1 to 100 %><option value="<%=I%>">头像<%=I%></option><%next%

></SELECT>

/给区域里加上滚动条;scrollbar 滚动条。
<DIV style= "OVERFLOW: scroll; WIDTH: 752px; HEIGHT: 300px "> <div>

/cint值的运用
rs("shuliang") = cint(shuliang) + cint(rs("shuliang")) 否则 0 = 2 + 0 ,rs=20

/限制只读20个字符出来
<%=left(rst("biaoti"),20)%>
/语句循环
<%
set rst=server.createobject("adodb.recordset")
sql="select * from room where hotelid="&request("hotel_id")
rst.open sql,conn,3,1
%>
<%if not rst.eof then
do while not rst.eof %>
<%=rs("word")%>
<% rst.movenext
loop
else
response.write "<tr><td colspan=13><marquee scrolldelay=120 behavior=alternate>没

有找到任何记录!!!</marquee></td></tr>"
end if
rst.close
set rst=nothing
%>

/如果字符超过80 则
<%if len(rs("memo"))>80 then
response.write"…"
end if
%>

/用<span赋予字符css属性>
<span style="margin-left: 50px">

/表格 超链接
<td onclick="window.open('reg.asp', '_blank')" style="CURSOR:hand" width="37%">

/装数据
admin_name=trim(request("admin_name"))
sql="select * from admin_user where name='"&admin_name&"'"

username=Request.Form("username")
sql="select * from admin where admin=" & sqlstr(username) & " and password=" &

sqlstr(password) & ""

数字型 每个字符占一个空间
" & session("XXX") ' " & request("id") & " ' '张三' where id=4
字符型 真个字符占一个空间
'" & session("XXX") & "'

/输出时候asp?request的格式
response.redirect "dingdan_edit.asp?dingdan_id=" & request("dingdan_id")

/asp 判断。
if class2="0" or class2="" then
response.write"<SCRIPT language=JavaScript>alert('请正确选择二级分

类');javascript:history.go(-1)</SCRIPT>"
response.end
end if

//插TD的CSS背景
style="BACKGROUND-IMAGE: url(images/sky_bg1.jpg); PADDING-TOP: 467px; BACKGROUND-

REPEAT: repeat-x"

//透明的PNG背景
<script type="text/javascript" language="JavaScript">
//<![CDATA[
function setPng24(obj) {
obj.width = obj.height=1;
obj.className = obj.className.replace(//bpng24/b/i,'');
obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader

(src='"+ obj.src+"', sizingMethod='image');"
obj.src = '';
return '';
}

//]]>
</script>
<style type="text/css">
<!--
.png24 { tmp:expression(setPng24(this)); }
body {
background-color: #000000;
}
-->
</style>
<img src="bg.png" alt="Smart Search" width="707" height="248" class="png24" />

//广告
http://edu.qq.com/a/20081120/000095.htm?

//下拉框跳转URL (要以http://www.XXX.CC//格式)
onchange="javascript:window.open(s1.value);"

//表单提交检查
<SCRIPT language=javascript>
<!--
function CheckForm()
{
if(document.thisForm.username.value.length<1)
{
alert("用户名称不能为空!");
document.thisForm.username.focus();
document.thisForm.username.select();
return false;
}
var filter=/^/s*[.A-Za-z0-9_-]{5,15}/s*$/;
if (!filter.test(document.thisForm.username.value)) {
alert("用户名填写不正确,请重新填写!可使用的字符为(A-Z a-z 0-9 _ -

.)长度不小于5个字符,不超过15个字符,注意不要使用空格。");
document.thisForm.username.focus();
document.thisForm.username.select();
return (false);
}

if(document.thisForm.password.value.length<6)
{
alert("用户密码不能为空或少于6位!");
document.thisForm.password.focus();
document.thisForm.password.select();
return false;
}
if(document.thisForm.password1.value.length<6)
{
alert("确认密码不能为空或少于6位!");
document.thisForm.password1.focus();
document.thisForm.password1.select();
return false;
}
if (document.thisForm.password.value!=document.thisForm.password1.value ){
alert("两次填写的密码不一致,请重新填写!");
document.thisForm.password.focus();
document.thisForm.password.select();
return (false);
}
if(document.thisForm.wenti.value.length == 0)
{
alert("请选择一个密码问题!");
return false;
}
if(document.thisForm.Answer.value.length<1)
{
alert("问题答案不能为空!");
document.thisForm.Answer.focus();
document.thisForm.Answer.select();
return false;
}
if(document.thisForm.xingming.value.length<1)
{
alert("姓名不能为空!");
document.thisForm.xingming.focus();
document.thisForm.xingming.select();
return false;
}
if(document.thisForm.Mobile.value.length<11)
{
alert("手机位数不对!");
document.thisForm.Mobile.focus();
document.thisForm.Mobile.select();
return false;
}
if(document.thisForm.Phone.value.length<7)
{
alert("电话位数不对!");
document.thisForm.Phone.focus();
document.thisForm.Phone.select();
return false;
}
if(document.thisForm.Email.value.length<1)
{
alert("邮箱不能为空!");
document.thisForm.Email.focus();
document.thisForm.Email.select();
return false;
}
var vmail,vstr;
vstr= "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_@. ";
vmail=document.thisForm.Email.value;

if(vmail!= " "){

for (var i=0; i < vmail.length; i++)
{
var letter = vmail.charAt(i).toLowerCase();
if (vstr.indexOf(letter) != -1)
continue;
alert( "E-Mail 中含有无效字符: " + letter);
document.thisForm.Email.focus();
document.thisForm.Email.select();
return false;
break;
}

if (vmail.indexOf( "@")==-1)
{
alert( "Email地址无效! ");
return false;
}

if (vmail.indexOf( ".")==-1)
{
alert( "Email地址无效! ");
return false;
}

}

}
//-->
</SCRIPT>

整理出一些运用ASP+ACCESS过程的技巧或需注意的地方。

-右键设计表格,主键为类型为自动编号。

- //<form method="post" action="add.asp">// 要在<tr>之前 ,</form>在<tr>之后。则不会破坏表格原型。

- <input>里面要注明id,和name.如//<input name="name" type="text" id="name" size="58">//貌似ASP只识别name.

-<a href=room_del.asp?id=<%=rst("room_id")%>&hotel_id=<%=rst("hotel_id")%>>
这句话是把你当前room_ID和hotel_id同时提交到room_del.asp页面里,让sort.asp对当前你提交过去的id进行相关操作。
比如“删除”或“修改”,都需要先提交一个ID号过去,他才知道你要删除或修改哪条记录。

-rs , rst对象实例名字,和变量名一样的道理,你可以找到Set rs = Server.CreateObject("ADODB.RecordSet") 或 Set rst =

Server.CreateObject("ADODB.RecordSet") ,
你也可以把rs,rst换成其他名字
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐