网页javascript精华代码集(2)
13.内框架<iframe>使用
iframe标记的使用格式是:
<iframe src=url width=x height=x scrolling=[option] frameborder=x
name=main></iframe>
src:文件的路径,既可是html文件,也可以是文本、asp等
width、height:内部框架区域的宽与高;
scrolling:当src的指定的html文件在指定的区域不显不完时,滚动选项,如果设置为no,则不出现滚动条;如为auto:则自动出现滚动条;如为yes,则显示; frameborder:区域边框的宽度,为了让“内部框架“与邻近的内容相融合,常设置为0。
name:框架的名字,用来进行识别。
比如: 当你想用父框架控制内部框架时,可以使用: target=框架的名字来控制。
例子:<iframe name=mm src=http://bbs.055.cn;; width=100% height=100% marginwidth=0 marginheight= ... ot; frameborder=0 scrolling=no></iframe>
14.自动跳转
在源代码中的<head>…</head>加入如下代码:
<meta http-equiv=refreshcontent=3;url=http://bbs.055.cn; charset=gb2312>
说明:content=3 表示3秒刷新到url
15.如何改变链接的鼠标形状
只需在链接上加上这一代码就行的了
或者跟上面的用css写也行
style=cursor:hand style=cursor:crosshair
style=cursor:text style=cursor:wait
style=cursor:move style=cursor:help
style=cursor:e-resize
style=cursor:n-resize
style=cursor:nw-resize style=cursor:w-resize
style=cursor:s-resize
style=cursor:se-resize
style=cursor:sw-resize
以上代码你只需要加到连接或是页面的style区里就可以实现鼠标多样化。
16.全屏显示
<form>
<div align=center>
<input type=button name=fullscreen value=全屏显示 onclick=window.open(document.location, 'big', 'fullscreen=yes')>
</div>
</form>
把它放到<body>区中。
17.设为首页
<script language=javascript>
<!--
function defaul_home(){
this.home.style.behavior='url(#default#homepage)';this.home.sethomepage([url]http://bbs.055.cn/[/url]';
}
var focusok=false;
if (navigator.appname == netscape{
focusok=true;
}
vers=navigator.appversion;
if (navigator.appname == microsoft internet explorer{
pos=vers.lastindexof('.');
vers=vers.substring(pos-1,vers.length);
}
proper_version=parsefloat(vers);
if(proper_version>=5){
focusok=true;
}
function launchstock1(htmlurl){
var stock=window.open(htmlurl,stock,top=2,left=2,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,
resizable=no,width=700,height=510;
if(focusok){
stock.focus();
}
return true;
}
function launchstock(){
var stock=window.open(,stock,top=2,left=2,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,
resizable=no,width=700,height=510;
if(focusok){
stock.focus();
}
return true;
}
// -->
</script>
<a href=# name=home onclick=defaul_home(); title===e代时光==>设为首页</a>
18.这里是加入收藏夹的代码
<a href=# onclick=window.external.addfavorite([url]http://bbs.055.cn[/url]';.'拂晓雅阁') target=_self title=拂晓雅阁>加入收藏夹</a>
19.flash图片效果
以下代码加入<head>区域
<script language=javascript>
<!--
function makevisible(cur,which){
if (which==0)
cur.filters.alpha.opacity=100
else
cur.filters.alpha.opacity=20
}
//-->
</script>
以下代码加入<body>区域
<img src=http://bbs.055.cn/images/logo.gif;; style=filte ... nbsp;onmouseover=makevisible(this,0) onmouseout=makevisible(this,1) width=63 height=56> //图片地址请自己改
20.load 进度条
<table cellspacing=0 cellpadding=0 bgcolor=#ffffff width=40% id=p><tr><td>
<table cellspacing=0 cellpadding=0 bgcolor=#0000ff height=18 id=q><tr><td></td></tr></table></td></tr></table>
</center>
<script language=javascript>
var r = 0; load();
function load() {r = r + 2; q.style.width = r + %; time= settimeout(load(),50);
if (r > 100) {cleartimeout(time); p.style.width=0}}
</script>
27 全屏
<script language=javascript>
window.open('index.asp','','fullscreen=1');
</script>
21.背景图片滚动
<body scroll=no background=images/bg.jpg link=#00ff00 alink=#ff0000 vlink=#00ff00 bgcolor=#000080 topmargin=8>
<script language=javascript>
var backgroundoffset = 0;
var bgobject = eval('document.body');
function scrollbg(maxsize) {backgroundoffset = backgroundoffset + 1;
if (backgroundoffset > maxsize) backgroundoffset = 0;
bgobject.style.backgroundposition = 0 + backgroundoffset;}
var scrolltimer = window.setinterval(scrollbg(410), 20)
</script>
22.网页不会被缓存
html网页
<meta http-equiv=pragma content=no-cache>
<meta http-equiv=cache-control content=no-cache, must-revalidate>
<meta http-equiv=expires content=wed, 26 feb 1997 08:21:57 gmt>
或者<meta http-equiv=expires content=0>
asp网页
response.expires = -1
response.expiresabsolute = now() - 1
response.cachecontrol = no-cache
php网页
header(expires: mon, 26 jul 1997 05:00:00 gmt;
header(cache-control: no-cache, must-revalidate;
header(pragma: no-cache;
23.
<%
'定义数据库连接的一些常量
const adopenforwardonly = 0 '游标只向前浏览记录,不支持分页、recordset、bookmark
const adopenkeyset = 1 '键集游标,其他用户对记录说做的修改将反映到记录集中,但其他用户增加或删除记录不会反映到记录集中。支持分页、recordset、bookmark
const adopendynamic = 2 '动态游标功能最强,但耗资源也最多。用户对记录说做的修改,增加或删除记录都将反映到记录集中。支持全功能浏览(access不支持)。
const adopenstatic = 3 '静态游标,只是数据的一个快照,用户对记录说做的修改,增加或删除记录都不会反映到记录集中。支持向前或向后移动
const adlockreadonly = 1 '锁定类型,默认的,只读,不能作任何修改
const adlockpessimistic = 2 '当编辑时立即锁定记录,最安全的方式
const adlockoptimistic = 3 '只有在调用update方法时才锁定记录集,而在此前的其他操作仍可对当前记录进行更改、插入和删除等
const adlockbatchoptimistic = 4 '当编辑时记录不会被锁定,而更改、插入和删除是在批处理方式下完成的
const adcmdtext = &h0001
const adcmdtable = &h0002
%>
24.最小化、最大化、关闭窗口
<object id=hh1 classid=clsiddb880a6-d8ff-11cf-9377-00aa003b7a11>
<param name=command value=minimize></object>
<object id=hh2 classid=clsiddb880a6-d8ff-11cf-9377-00aa003b7a11>
<param name=command value=maximize></object>
<object id=hh3 classid=clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11>
<param name=command value=close></object>
<input type=button value=最小化 onclick=hh1.click()>
<input type=button value=最大化 onclick=hh2.click()>
<input type=button value=关闭 onclick=hh3.click()>
说明:本例适用于ie
25.判断上一页的来源
asp页:
request.servervariables(http_referer
java script:
document.referrer
26.光标是停在文本框文字的最后
<script language=javascript>
function cc()
{
var e = event.srcelement;
var r =e.createtextrange();
r.movestart('character',e.value.length);
r.collapse(true);
r.select();
}
</script>
<input type=text name=text1 value=123 onfocus=cc()>
说明:适用于表格数据提交
文章整理:iocblog
版权申明:本站文章均来自网络,如有侵权,请联系我们,我们收到后立即删除,谢谢!
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有。