一些常用的JS代码收集

1. οncοntextmenu="window.event.returnvalue=false" 将彻底屏蔽鼠标右键
<table border οncοntextmenu=return(false)><td>no</table> 可用于Table
2. <body onselectstart="return false"> 取消选取、防止复制
3. οnpaste="return false" 不准粘贴
4. οncοpy="return false;" oncut="return false;" 防止复制
5. <link rel="Shortcut Icon" href="favicon.ico"> IE地址栏前换成自己的图标
6. <link rel="Bookmark" href="favicon.ico"> 可以在收藏夹中显示出你的图标
7. <input style="ime-mode:-Disabled"> 关闭输入法
8. 永远都会带着框架
<script language="javascript"><!--
if (window == top)top.location.href = "frames.htm"; //frames.htm为框架网页
// --></script>
9. 防止被人frame
<SCRIPT LANGUAGE=javascript><!--
if (top.location != self.location)top.location=self.location;
// --></SCRIPT>
10. 网页将不能被另存为
<noscript><iframe src=*.html></iframe></noscript>
11. <input type=button value=查看网页源代码
οnclick="window.location = `view-source:`+ http://www.51js.com/`";>
12.删除时确认
<a href=`javascript:if(confirm("确实要删除吗?"location="boos.asp?&areyou=删除&page=1"`>删
除</a>
13. 取得控件的绝对位置
//javascript
<script language="javascript">
function getIE(E){
var t=e.offsetTop;
var l=e.offsetLeft;
while(e=e.offsetParent){
t+=e.offsetTop;
l+=e.offsetLeft;
}
alert("top="+t+"/nleft="+l);
}
</script>
//VBScript
<script language="VBScript"><!--
function getIE()
dim t,l,a,b
set a=document.all.img1
t=document.all.img1.offsetTop
l=document.all.img1.offsetLeft
while a.tagName<>"BODY"
set a = a.offsetParent
t=t+a.offsetTop
l=l+a.offsetLeft
wend
msgbox "top="&t&chr(13)&"left="&l,64,"得到控件的位置"
end function
--></script>
14. 光标是停在文本框文字的最后
<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" οnfοcus="cc()">
15. 判断上一页的来源
javascript:
document.referrer
16. 最小化、最大化、关闭窗口
<object id=hh1 classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">
<param name="Command" value="Minimize"></object>
<object id=hh2 classid="clsid:ADB880A6-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=最小化 οnclick=hh1.Click()>
<input type=button value=最大化 οnclick=hh2.Click()>
<input type=button value=关闭 οnclick=hh3.Click()>

隐去浏览器中当鼠标移到图片上跳出的工具栏
<img galleryimg="no">
或者
<head>
<meta http-equiv="imagetoolbar" content="no">
</head>
打开,另存为,属性,打印"等14个JS代码

■打开■
<input name=Button onClick=document.all.WebBrowser.ExecWB(1,1) type=button value=打开>
<OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT>
■另存为■
<input name=Button onClick=document.all.WebBrowser.ExecWB(4,1) type=button value=另存为><OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT>
■属性■
<input name=Button onClick=document.all.WebBrowser.ExecWB(10,1) type=button value=属性><OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT>
■打印■
<input name=Button onClick=document.all.WebBrowser.ExecWB(6,1) type=button value=打印><OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT>
■页面设置■
<input name=Button onClick=document.all.WebBrowser.ExecWB(8,1) type=button value=页面设置><OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT>
■刷新■
<input type=button value=刷新 name=refresh οnclick="window.location.reload()">
■导入收藏■
<input type="button" name="Button" value="导入收藏夹" onClick=window.external.ImportExportFavorites(true,);>
■导出收藏■
<input type="button" name="Button3" value="导出收藏夹" onClick=window.external.ImportExportFavorites(false,);>
■加入收藏■
<INPUT name=Button2 οnclick="window.external.AddFavorite(location.href, document.title)" type=button value=加入收藏夹>
■整理收藏夹■
<INPUT name=Submit2 οnclick="window.external.ShowBrowserUI(OrganizeFavorites, null)" type=button value=整理收藏夹>
■查看原文件■
<INPUT name=Button οnclick=window.location = "view-source:" + window.location.href type=button value=查看源文件>
■语言设置■
<INPUT name=Button οnclick="window.external.ShowBrowserUI(LanguageDialog, null)" type=button value=语言设置>
■前进■
<INPUT name=Submit οnclick=history.go(1) type=submit value=前进>
■后退■
<INPUT name=Submit2 οnclick=history.go(-1) type=submit value=后退>

1.获得系统时间:
<%=now()%>
2.取得来访用的IP:
<%=request.server<I>var</I>iables("remote_host")%>
3.获得系统,浏览器版本:
<<I>script</I>>
window.document.write("版本:"+navigator.appName+navigator.appVersion+" browser.")
</<I>script</I>>
4.去除IE混动条:
<body scroll="no">
<body style="overflow-y:hidden">
5.进入网站,跳出广告:
<<I>script</I> language="java<I>script</I>">
<!--
<!-- 注意更改文件所在路径-->
window.open('http://www.XXXXXX.com<;I>&#</I>39;,'','height=200,width=300,top=0,left=30');
// -->
</<I>script</I>>
6.随机数:
<%randomize%>
<%=(int(rnd()*n)+1)%>
N为可改变数
7.向上混动代码:
<marquee direction="up" scrolldelay="200" style="font-size: 9pt; color: #FF0000; line-height: 150%; font-style:italic; font-weight:bold" scrollamount="2" width="206" height="207" bgcolor="#FFFF00">hhhhhhhhhhhhhhhhhhh</marquee>
8.自动关闭网页:
<<I>script</I> LANGUAGE="java<I>script</I>">
<!--
setTimeout('window.close();', 10000); //60秒后关闭
// -->
</<I>script</I>>
<p align="center">本页10秒后自动关闭,请注意刷新页面</p>
9.随机背景音乐:
<%randomize%>
<bgsound src="mids/<%=(int(rnd()*60)+1)%>.mid" loop="-1">

可以修改数字,限制调用个数,我这里是60个.
10.自动刷新本页面:
<<I>script</I>>
<!--

<I>var</I> limit="0:10"

if (document.images){
<I>var</I> parselimit=limit.split(":")
parselimit=parselimit[0]*60+parselimit[1]*1
}
<I>function</I> beginrefresh(){
if (!document.images)
return
if (parselimit==1)
window.location.reload()
else{
parselimit-=1
curmin=Math.floor(parselimit/60)
cursec=parselimit%60
if (curmin!=0)
curtime=curmin+"分"+cursec+"秒后重刷本页!"
else
curtime=cursec+"秒后重刷本页!"
window.status=curtime
setTimeout("beginrefresh()",1000)
}
}

window.<I>onload</I>=beginrefresh
<I>file:</I>//-->
</<I>script</I>>
11.ACCESS数据库连接:
<%
option explicit
dim startime,endtime,conn,connstr,db
startime=timer()
'更改数据库名字
db="data/dvBBS5.mdb"
Set conn = Server.CreateObject("ADODB.Connection")
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(db)
'如果你的服务器采用较老版本Access驱动,请用下面连接方法
'connstr="driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.MapPath(db)
conn.Open connstr
<I>function</I> CloseDatabase
Conn.close
Set conn = Nothing
End <I>function</I>
%>
12.SQL数据库连接:
<%
option explicit
dim startime,endtime,conn,connstr,db
startime=timer()
connstr="driver={SQL Server};server=HUDENQ-N11T33NB;uid=sa;pwd=xsfeihu;database=dvbbs"
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open connstr
<I>function</I> CloseDatabase
Conn.close
Set conn = Nothing
End <I>function</I>
%>
13.用键盘打开网页代码:
<<I>script</I> language="java<I>script</I>">
<I>function</I> ctlent(eventobject)
{
if((event.ctrlKey && window.event.keyCode==13)||(event.altKey && window.event.keyCode==83))
{
window.open('网址','','')
}
}
这里是Ctrl+Enter和Alt+S的代码自己查下键盘的ASCII码再换就行
14.让层不被控件复盖代码:
<div z-Index:2><object ***></object></div> # 前面
<div z-Index:1><object ***></object></div> # 后面
<div id="Layer2" style="position:absolute; top:40;width:400px; height:95px;z-index:2"><table height=100% width=100% bgcolor="#ff0000"><tr><td height=100% width=100%></td></tr></table><<I>iframe</I> width=0 height=0></<I>iframe</I>></div>
<div id="Layer1" style="position:absolute; top:50;width:200px; height:115px;z-index:1"><<I>iframe</I> height=100% width=100%></<I>iframe</I>></div>
15.动网FLASH广告代码:
<object classid="clsid 27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="468" height="60"><param name=movie value="images/yj16d.swf"><param name=quality value=high><embed src="images/dvbanner.swf" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash";;;;;;;; type="application/x-shockwave-flash" width="468" height="60"></embed></object>
16.VBS弹出窗口小代码:
<<I>script</I> language=vb<I>script</I>>
msgbox"你还没有注册或登陆论坛","0","精品论坛"
location.href = "login.asp"
</<I>script</I>>
17.使用FSO修改文件特定内容的函数
<I>function</I> FSOchange(filename,Target,String)
Dim objFSO,objCountFile,FiletempData
Set objFSO = Server.CreateObject("<I>script</I>ing.FileSystemObject"
Set objCountFile = objFSO.OpenTextFile(Server.MapPath(filename),1,True)
FiletempData = objCountFile.ReadAll
objCountFile.Close
FiletempData=Replace(FiletempData,Target,String)
Set objCountFile=objFSO.CreateTextFile(Server.MapPath(filename),True)
objCountFile.Write FiletempData
objCountFile.Close
Set objCountFile=Nothing
Set objFSO = Nothing
End <I>function</I>
18.使用FSO读取文件内容的函数
<I>function</I> FSOFileRead(filename)
Dim objFSO,objCountFile,FiletempData
Set objFSO = Server.CreateObject("<I>script</I>ing.FileSystemObject"
Set objCountFile = objFSO.OpenTextFile(Server.MapPath(filename),1,True)
FSOFileRead = objCountFile.ReadAll
objCountFile.Close
Set objCountFile=Nothing
Set objFSO = Nothing
End <I>function</I>
19.使用FSO读取文件某一行的函数
<I>function</I> FSOlinedit(filename,lineNum)
if linenum < 1 then exit <I>function</I>
dim fso,f,temparray,tempcnt
set fso = server.CreateObject("<I>script</I>ing.filesystemobject"
if not fso.fileExists(server.mappath(filename)) then exit <I>function</I>
set f = fso.opentextfile(server.mappath(filename),1)
if not f.AtEndofStream then
tempcnt = f.readall
f.close
set f = nothing
temparray = split(tempcnt,chr(13)&chr(10))
if lineNum>ubound(temparray)+1 then
exit <I>function</I>
else
FSOlinedit = temparray(lineNum-1)
end if
end if
end <I>function</I>
20.使用FSO写文件某一行的函数
<I>function</I> FSOlinewrite(filename,lineNum,Linecontent)
if linenum < 1 then exit <I>function</I>
dim fso,f,temparray,tempCnt
set fso = server.CreateObject("<I>script</I>ing.filesystemobject")
if not fso.fileExists(server.mappath(filename)) then exit <I>function</I>
set f = fso.opentextfile(server.mappath(filename),1)
if not f.AtEndofStream then
tempcnt = f.readall
f.close
temparray = split(tempcnt,chr(13)&chr(10))
if lineNum>ubound(temparray)+1 then
exit <I>function</I>
else
temparray(lineNum-1) = lineContent
end if
tempcnt = join(temparray,chr(13)&chr(10))
set f = fso.createtextfile(server.mappath(filename),true)
f.write tempcnt
end if
f.close
set f = nothing
end <I>function</I>
21.使用FSO添加文件新行的函数
<I>function</I> FSOappline(filename,Linecontent)
dim fso,f
set fso = server.CreateObject("<I>script</I>ing.filesystemobject")
if not fso.fileExists(server.mappath(filename)) then exit <I>function</I>
set f = fso.opentextfile(server.mappath(filename),8,1)
f.write chr(13)&chr(10)&Linecontent
f.close
set f = nothing
end <I>function</I>
22.读文件最后一行的函数
<I>function</I> FSOlastline(filename)
dim fso,f,temparray,tempcnt
set fso = server.CreateObject("<I>script</I>ing.filesystemobject")
if not fso.fileExists(server.mappath(filename)) then exit <I>function</I>
set f = fso.opentextfile(server.mappath(filename),1)
if not f.AtEndofStream then
tempcnt = f.readall
f.close
set f = nothing
temparray = split(tempcnt,chr(13)&chr(10))
FSOlastline = temparray(ubound(temparray))
end if
end <I>function</I>

23.js常用代码

前进 javascript:history.forward(1)

后退 javascript:history.back(1)

停止 javascript ocation.stop()

刷新 javascript ocation.reload()

打印 javascript:window.print()

主页 http://首页的地址

邮件 mailto:电子邮件地址

24.点击返回上页代码:
<form>
<p><input TYPE="button" value="返回上一步" <I>onCLICK</I>="history.back(-1)"></p>
</form>
25.点击刷新代码:
<form>
<p><input TYPE="button" value="刷新按钮一" <I>onCLICK</I>="ReloadButton()"></p>
</form>
<<I>script</I> language="java<I>script</I>"><!--
<I>function</I> ReloadButton(){location.href="allbutton.htm";}
// --></<I>script</I>>

26.点击刷新代码2:
<form>
<p><input TYPE="button" value="刷新按钮二" <I>onClick</I>="history.go(0)"> </p>
</form>

<form>
<p><input TYPE="button" value="打开一个网站" <I>onCLICK</I>="HomeButton()"></p>
</form>
<<I>script</I> language="java<I>script</I>"><!--
<I>function</I> HomeButton(){location.href="http://nettrain.126.com";;;;;;;;}
// --></<I>script</I>>

27.弹出警告框代码:
<form>
<p><input TYPE="button" value="弹出警告框" <I>onCLICK</I>="AlertButton()"></p>
</form>
<<I>script</I> language="java<I>script</I>"><!--
<I>function</I> AlertButton(){window.alert("要多多光临呀!");}
// --></<I>script</I>>

28.状态栏信息
<form>
<p><input TYPE="button" value="状态栏信息" <I>onCLICK</I>="StatusButton()"></p>
</form>
<<I>script</I> language="java<I>script</I>"><!--
<I>function</I> StatusButton(){window.status="要多多光临呀!";}
// --></<I>script</I>>

29.背景色变换
<form>
<p><input TYPE="button" value="背景色变换" <I>onClick</I>="BgButton()"></p>
</form>
<<I>script</I>><I>function</I> BgButton(){
if (document.bgColor=='#00ffff')
{document.bgColor='#ffffff';}
else{document.bgColor='#00ffff';}
}
</<I>script</I>>

30.点击打开新窗口
<form>
<p><input TYPE="button" value="打开新窗口" <I>onCLICK</I>="NewWindow()"></p>
</form>
<<I>script</I> language="java<I>script</I>"><!--
<I>function</I> NewWindow(){window.open("http://www.lomor.net";;;;;;;,"","height=240,width=340,status=no,location=no,toolbar=no,directories=no,menubar=no");}
// --></<I>script</I>></body>
31.分页代码:
<%''本程序文件名为:Pages.asp%>
<%''包含ADO常量表文件adovbs.inc,可从"/Program Files/Common Files/System/ADO"目录下拷贝%>
<!--#Include File="adovbs.inc"-->
<%''*建立数据库连接,这里是Oracle8.05数据库
Set conn=Server.CreateObject("ADODB.Connection"
conn.Open "Provider=msdaora.1;Data Source=YourSrcName;User ID=YourUserID;Password=YourPassword;"

Set rs=Server.CreateObject("ADODB.Recordset" ''创建Recordset对象
rs.CursorLocation=adUseClient ''设定记录集指针属性
''*设定一页内的记录总数,可根据需要进行调整
rs.PageSize=10

''*设置查询语句
StrSQL="Select ID,姓名,住址,电话 from 通讯录 order By ID"
rs.Open StrSQL,conn,adOpenStatic,adLockReadOnly,adCmdText
%>
<HTML>
<HEAD>
<title>分页示例</title>
<<I>script</I> language=java<I>script</I>>
//点击"[第一页]"时响应:
<I>function</I> PageFirst()
{
document.MyForm.CurrentPage.selectedIndex=0;
document.MyForm.CurrentPage.onchange();
}
//点击"[上一页]"时响应:
<I>function</I> PagePrior()
{
document.MyForm.CurrentPage.selectedIndex--;
document.MyForm.CurrentPage.onchange();
}
//点击"[下一页]"时响应:
<I>function</I> PageNext()
{
document.MyForm.CurrentPage.selectedIndex++;
document.MyForm.CurrentPage.onchange();
}
//点击"[最后一页]"时响应:
<I>function</I> PageLast()
{
document.MyForm.CurrentPage.selectedIndex=document.MyForm.CurrentPage.length-1;
document.MyForm.CurrentPage.onchange();
}
//选择"第?页"时响应:
<I>function</I> PageCurrent()
{ //Pages.asp是本程序的文件名
document.MyForm.action='Pages.asp?Page='+(document.MyForm.CurrentPage.selectedIndex+1)
document.MyForm.submit();
}
</<I>script</I>>
</HEAD>
<BODY bgcolor="#ffffcc" link="#008000" vlink="#008000" alink="#FF0000"">

<%IF rs.Eof THEN
Response.Write("<font size=2 color=#000080>[数据库中没有记录!]</font>"
ELSE
''指定当前页码
If Request("CurrentPage")="" Then
rs.AbsolutePage=1
Else
rs.AbsolutePage=CLng(Request("CurrentPage"))
End If

''创建表单MyForm,方法为Get
Response.Write("<form method=Get name=MyForm>")
Response.Write("<p align=center><font size=2 color=#008000>")
''设置翻页超链接
if rs.PageCount=1 then
Response.Write("[第一页] [上一页] [下一页] [最后一页] ")
else
if rs.AbsolutePage=1 then
Response.Write("[第一页] [上一页] ")
Response.Write("[<a href=java<I>script</I> ageNext()>下一页</a>] ")
Response.Write("[<a href=java<I>script</I> ageLast()>最后一页</a>] ")
else
if rs.AbsolutePage=rs.PageCount then
Response.Write("[<a href=java<I>script</I> ageFirst()>第一页</a>] ")
Response.Write("[<a href=java<I>script</I>:PagePrior()>上一页</a>] ")
Response.Write("[下一页] [最后一页] ")
else
Response.Write("[<a href=java<I>script</I>:PageFirst()>第一页</a>] ")
Response.Write("[<a href=java<I>script</I>:PagePrior()>上一页</a>] ")
Response.Write("[<a href=java<I>script</I>:PageNext()>下一页</a>] ")
Response.Write("[<a href=java<I>script</I>:PageLast()>最后一页</a>] ")
end if
end if
end if

''创建下拉列表框,用于选择浏览页码
Response.Write("第<select size=1 name=CurrentPage οnchange=PageCurrent()>")
For i=1 to rs.PageCount
if rs.AbsolutePage=i then
Response.Write("<option selected>"&i&"</option>") ''当前页码
else
Response.Write("<option>"&i&"</option>")
end if
Next
Response.Write("</select>页/共"&rs.PageCount&"页共"&rs.RecordCount&"条记录</font><p>")
Response.Write("</form>")

''创建表格,用于显示
Response.Write("<table align=center cellspacing=1 cellpadding=1 border=1")
Response.Write(" bordercolor=#99CCFF bordercolordark=#b0e0e6 bordercolorlight=#000066>")

Response.Write("<tr bgcolor=#ccccff bordercolor=#000066>")

Set Columns=rs.Fields

''显示表头
For i=0 to Columns.Count-1
Response.Write("<td align=center width=200 height=13>")
Response.Write("<font size=2><b>"&Columns(i).name&"</b></font></td>")
Next
Response.Write("</tr>")
''显示内容
For i=1 to rs.PageSize
Response.Write("<tr bgcolor=#99ccff bordercolor=#000066>")
For j=0 to Columns.Count-1
Response.Write("<td><font size=2>"&Columns(j)&"</font></td>")
Next
Response.Write("</tr>")

rs.movenext
if rs.EOF then exit for
Next

Response.Write("</table>")

END IF
%>
</BODY>
</HTML
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值