700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > jsp/html开发中常用的JS代码和页面特效代码

jsp/html开发中常用的JS代码和页面特效代码

时间:2023-01-07 00:16:36

相关推荐

jsp/html开发中常用的JS代码和页面特效代码

1.jsp/html开发中常用的JS代码

1、后退 前进

<input type="button" value="后退" onClick="history.go(-1)"> <input type="button" value="前进" onClick="history.go( 1 );return true;">

2、返回

<input type="button" value="返回上一步" onClick="history.back(-1)">

3、查看源码

<input type="button" name="view" value="查看源码" onClick="window.location="view-source:" +window.location.href">

4、禁止查看源码

<body oncontextmenu="return false"></body>

5、刷新按钮一

<input type="button" value="刷新按钮一" onClick="ReloadButton()"> <script>function ReloadButton(){location.href="i001.htm";}</script>

刷新按钮二

<input type="button" value="刷新按钮二" onClick="history.go(0)">

6、回首页按钮

<input type="button" value="首页" onClick="HomeButton()"> <script>function HomeButton(){location.href=;}</script>

7、弹出警告框

<input type="button" value="弹出警告框" onClick="AlertButton()"> <script>function AlertButton(){window.alert("要多多光临呀!");}</script>

8、状态栏信息

<input type="button" value="状态栏信息" onClick="StatusButton()"> <script>function StatusButton(){window.status="要多多光临呀!";}</script>

9、背景色变换

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

10、打开新窗口

<input type="button" value="打开新窗口" onClick="NewWindow()"> <script>function NewWindow(){window.open("c01.htm","","height=240,width=340,status=no,location=no,toolbar=no,directories=no,menubar=no");} </script>

11、窗口最小化

<OBJECT id="min" type="application/x-oleobject" classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11"><PARAM name="Command" value="Minimize"></OBJECT><button onClick="min.Click()">窗口最小化</button>

12、全屏代码

<input type="BUTTON" name="FullScreen" value="全屏显示" onClick="window.open(document.location, 'butong_net', 'fullscreen')">

13、关闭窗口

<OBJECT id=closes type="application/x-oleobject" classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11"><param name="Command" value="Close"></object><input type="button" value="关闭窗口" onClick="closes.Click();">

关闭窗口

<input type=button value=关闭窗口 onClick="javascript:self.close()">

14、最大化

<object id=big classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11"> <param name="Command" value="Maximize"></object><input type=button value=最大化 onClick=big.Click()>

15、关闭输入法

<input style="ime-mode:disabled" value=关闭输入法>

16、链接按钮1

<input type="button" value="链接按钮1" onClick="window.open('/', 'Sample', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=yes,width=790,height=520,left=0,top=0')" name="input">

链接按钮2

<input type="BUTTON" NAME="Button" value="链接按钮2" onClick="showModalDialog('/')">

链接按钮3

<input type="submit" value="链接按钮3" onClick="location.href='/'">

17、警告框显示源代码

<BUTTON onClick=alert(document.documentElement.outerHTML) style="width:110">警告框显示源代码</BUTTON>

18、点击后按钮清空

<input type=button value='打印' onClick="this.style.visibility='hidden';window.print();">

19、打印

<input type=button value='打印' onClick="window.print();">

20、打印预览

<OBJECT classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height=0 id=wb name=wb width=0></OBJECT> <input type=button value=打印预览 onclick="wb.execwb(7,1)">

21、另存为

<input onClick="document.execCommand('saveas','true','常用代码.htm')" type=button value=另存为>

22、点击自动复制

<script>function oCopy(obj){obj.select();js=obj.createTextRange();js.execCommand("Copy")}</script> <input type="text" value="点击自动复制" onClick="oCopy(this)" size="11">

23、自动选中

<input value="自动选中" onFocus="this.select()" onMouseOver="this.focus()" size="11">

24、打开源代码

<BUTTON onClick="document.location = 'view-source:' + document.location" size="7">打开源代码</BUTTON>

25、新窗口延迟打开

<input type=button value=新窗口延迟打开 onClick=javascript:setTimeout("window.open('/')",10000)>

26、实现选中文本框里的前一半的内容

<input type="text" value="选中文本框里的前一半的内容" size=30 onmouseover="this.select();tR=document.selection.createRange();tR.moveEnd('character',-8);tR.select();"> <input type="text" value="选中部分内容,非IE可以用这个" size=30 onmouseover="this.selectionStart=this.value.length-4;this.selectionEnd=this.value.length">

27、点击清空文字

<input type="text" name="artist" size=14 value="点击清空文字" onmouseover=this.focus() onfocus=this.select() onclick="if(this.value=='点击清空文字')this.value=''">

点击清空文字

<input name=name size=11 value=点击清空文字 onMouseOver=this.focus() onblur="if (this.value =='') this.value='点击清空文字'" onFocus=this.select() onClick="if (this.value=='点击清空文字') this.value=''">

28、等于标题(title):

<input type="text" value="" id="aa" size="20"> <script>document.getElementById("aa").value=document.title;</script>

29、检测IE是否脱机

<input type="button" value="测试" onclick="alert(window.navigator.onLine)">

30、11种刷新按钮的方法

<input type=button value=刷新 onClick="history.go(0)"> <input type=button value=刷新 onClick="location.reload()"> <input type=button value=刷新 onClick="location=location"> <input type=button value=刷新 onClick="location.assign(location)"> <input type=button value=刷新 onClick="document.execCommand('Refresh')"> <input type=button value=刷新 onClick="window.navigate(location)"> <input type=button value=刷新 onClick="location.replace(location)"> <input type=button value=刷新 onClick="window.open('自身的文件','_self')"> <input type=button value=刷新 onClick=document.all.WebBrowser.ExecWB(22,1)> <OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT> <form action="自身的文件"><input type=submit value=刷新></form> <a id=a1 href="自身的文件"></a><input type=button value=刷新 onClick="a1.click()">

31、 打开网页

<a href="#" onClick=document.execCommand("open")>打开</a>

32、打开指定大小网页

<a onclick="window.open('i001.htm','','height=300,width=300,resizable=no,location=net');" href="">打开指定大小网页</a>

33、使用记事本编辑

<a href="#" onClick=location.replace("view-source:"+location)>使用 记事本 编辑</a>

34、另存为

<a href="#" onClick=document.execCommand("saveAs")>另存为</a>

35、打印

<a href="#" onClick=document.execCommand("print")>打印</a> <a href="javascript:window.print();">打印</a>

36、发送E-mail

<a href=mailto:429752806@>发送E-mail</a>

37、全选操作

<a href="#" onClick=document.execCommand("selectAll")>全选</a>

38、刷新

<a href="#" onClick=location.reload()>刷新1</a>

39、刷新

<a href="#" onClick=history.go(0)>刷新2</a>

40、查看源文件

<a href="#" onClick=location.replace("view-source:"+location)>查看源文件</a>

41、全屏显示

<a href="#" onClick=window.open(document.location,“url”,“fullscreen”)>全屏显示

42、internet选项

<a href="#" onClick=window.external.showBrowserUI("PrivacySettings",null)>internet选项</a>

43、单击右键将在新窗口中打开

<a href="#" oncontextmenu="window.open(this.href);return false;">单击右键将在新窗口中打开</a>

44、前进与后退

<a href="#" onClick=history.go(1)>前进1</a><a href="#" onClick=history.forward()>前进2</a><a href="#" onClick=history.go(-1)>后退1</a><a href="#" onClick=history.back()>后退2</a>

45、加入收藏,点击加入收藏夹,鼠标感应设为首页

<a href="#" onClick=window.external.showBrowserUI("OrganizeFavorites",null)>整理收藏夹</a><SPAN onClick="window.external.addFavorite('/','网页特效站点 ')" style="CURSOR: hand" title=网页特效站点>加入收藏</SPAN><a href="#" onClick="window.external.addFavorite('/','网页特效站点')">添加到收藏夹</A><a href="javascript:window.external.AddFavorite('/', '网页特效站点')">点击加入收藏夹</a><a href="#" onmouseover="window.external.addFavorite('/','网页特效站点')" target="_self" >鼠标感应收藏本站</a><a href="#" onmouseover="this.style.behavior='url(#default#homepage)';this.setHomePage('/js/');" target="_self">鼠标感应设为首页</a>

46、关闭窗口

<a href="javascript:window.close()">关闭窗口</a><a href="#" onClick=window.close();return false)>关闭窗口</a><a href="#" onClick=setTimeout(window.close(),3000)>3秒关闭本窗口</a><script> function shutwin(){ window.close(); return;} </script> <a href="javascript:shutwin();">关闭本窗口</a>

47、设为首页

<SPAN onClick="var strHref=window.location.href;this.style.behavior='url(#default#homepage)';this.setHomePage('/');" style="CURSOR: hand">设为首页</SPAN>

48、等于标题栏:

<script>document.write(document.title);</script>

49、收藏本页

<a href="javascript:void(0);" onClick='window.external.AddFavorite(location.href, document.title);'>收藏本页</a><a href="javascript:window.external.AddFavorite(document.location.href, document.title)">收藏本页</a><a href=javascript:window.external.addChannel("typhoon.cdf")>加入频道</a>

50、双击打开链接

<a href="i003.htm" onclick="return false;" ondblclick="window.open('i003.htm');">双击打开链接</a>

51、关闭窗口

<style>#close a:hover {background:url(javascript:window.opener=0;window.close());}</style><div id=close><a href="">关闭窗口</a></div>

52、链接禁止

<A HREF="javascript:void(0)" onMouseover="alert('对不起,禁止选中!')">链接禁止</A>

53、滚动条在左侧,

将<html>改为<HTML DIR="RTL">

54、网页半透明

<body style="filter:Alpha(Opacity=50)">

55、随机选择背景色

<body> <script> document.body.style.background=(["red","blue","pink","navy","gray","yellow","green","purple"])[parseInt(Math.random()*8)]; </script>

56、框架页中不显示滚动条:

<SCRIPT> self.moveTo(0,0) self.resizeTo(screen.availWidth,screen.availHeight) </SCRIPT>

57、防止网页被框架

<SCRIPT LANGUAGE=JAVASCRIPT> if (top.location !== self.location) { top.location=self.location; } </SCRIPT>

58、永远都会带着框架

<script language="javascript"><!-- if (window == top)top.location.href = "frame.htm"; //frame.htm为框架网页 // --></script>

59、窗口自动最大化

<script language="JavaScript"><!-- self.moveTo(0,0) self.resizeTo(screen.availWidth,screen.availHeight) //--></script>

60、打开窗口自动最大化

<OBJECT classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11" onreadystatechange="if (this.readyState==4) this.Click();" VIEWASTEXT><PARAM name="Command" value="Maximize"></OBJECT>

61、爽眼闪屏代码

<script>var color = new Array;color[1] = "black";color[2] = "white";for(x = 0; x <3; x++){document.bgColor = color[x];if(x == 2){x = 0;}}</script>

62、不能被另存为

<noscript><iframe src=*.html></iframe></noscript>

63、汉字字库调用

<script> for(i=19968;i<40870;i++)document.write(String.fromCharCode(i)); </script>

64、显示现在时间的脚本

<script language=vbscript>document.write now</script>

65、显示最后修改时间的脚本

<script>document.write(document.lastModified)</script>

66、按下F12键,直接返回首页

<script>function look(){ if(event.keyCode==123){document.location.href=/} } if(document.onkeydown==null) {document.onkeydown=look} </script>

67、端口检测

<img src="http://www.winliuxq/zza.jpg" onload="alert('端口可用')" onerror="alert('端口禁止')"...>

68、无法最小化的窗口

<body onblur='self.focus();'>

69、链接点外部css文件

<style>@import url("ie.css");</style>

70、内嵌式框架-网页中调用另外网页:

<object type="text/x-scriptlet" width="600" height="1000" data="/"></object>

71、刷新改变窗口大小

<OBJECT classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11" onreadystatechange="if (this.readyState==4) this.Click();" VIEWASTEXT><PARAM name="Command" value="Maximize"></OBJECT>

72、JavaScript实现网页竖虚线

<script>hei=120;d1=2;d2=2;cou=Math.floor(hei/(d1+d2)); document.write('<table cellspacing=0 cellpadding=0 width=1 height='+hei+'>'); for(i=0;i<cou;i++){document.write('<tr><td height='+d2+'><tr><td height='+d1+' bgcolor=333333>')}</script></table>

73、js翻页

<script>document.write("<a href="+location.href.replace(/\.html/g,"_2.html")+">2</a>");</script>

2.Html开发中常用的页面特效代码

加入连接:<a href="所要连接的相关地址">写上你想写的字</a>

在新窗口打开连接:<a href="相关地址" target="_blank">写上要写的字</a>

消除连接的下划线在新窗口打开连接:

写上你想写的字

移动字体(走马灯):<marquee>写上你想写的字</marquee>

字体加粗:<b>写上你想写的字</b>

字体斜体:<i>写上你想写的字</i>

字体下划线: <u>写上你想写的字</u>

字体删除线: <s>写上你想写的字</s>

字体加大: <big>写上你想写的字</big>

字体控制大小:<h1>写上你想写的字</h1> (其中字体大小可从h1-h5,h1最大,h5最小)

更改字体颜色:<font color="#value">写上你想写的字</font>(其中value值在000000与ffffff(16位进制)之间

贴音乐:<embed src=音乐地址 width=300 height=45 type=audio/mpeg autostart="false">

贴flash:<embed src="flash地址" width="宽度" height="高度">

原始文字样式:<pre>正文</pre>

换背景:<body background="背景图片地址">

固定帖子背景不随滚动条滚动:

<body background="背景图片地址" body bgproperties=fixed>

定制背景颜色:<body bgcolor="#value">(h1-6)背景音乐:<bgsound="背景音乐地址" loop=infinite>贴网页:<iframe src="相关地址" width="宽度" height="高度"></iframe>

----------------------------------------HTML特效代码--------------------------------

忽视右键:<body oncontextmenu="return false"> 或<body style="overflow-y:hidden">

加入背景音乐:

IE:<bgsound src="*.mid" loop=infinite>     NS:<embed src="*.mid" autostart=true hidden=true loop=true>    </embed>  

*.mid你的背景音乐的midi格式文件

简单的window.open方法:

<a href="#"  onclick="javascript :window.open(文件路径/文件名,newwindow,    toolbar=no,scrollbars=yes,resizable=no,top=0,left=0,    width=400,height=300);">文字或图片</a>

拉动页面时背景图不动 :

<style> body{background-image:url(logo.gif);     background-repeat:no-repeat;background-position:center}    </style><style> body{background-image:url(logo.gif);     background-repeat:no-repeat;background-position:center}    </style>

6。让浏览器在保存页面时保存失败:

<NOSCRIPT><iframe src="*.html"></iframe></NOSCRIPT> 

7。随机替换图片

<script>     document.write(<img src="img/+parseInt(Math.random()*(5))    +.gif"height="40" width="50">    </script>

图片文件名为0.gif 1.gif 2.gif 3.gif 4.gif

8。窗口定时关闭:

先将如下代码:

<script language="javascript">     function closeit() { setTimeout("self.close()",10000) //毫秒 }    </script>

然后再在标内加入如:<body onload="closeit()">

9。网页自动关闭:

<html><head><object id=closes type="application/x-oleobject"    classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11"><param name="Command" value="Close"></object></head><body onload="window.setTimeout(closes.Click(),10000)">    这个窗口会在10秒过后自动关闭,而且不会出现提示.</body></html>  

10。网页自动刷新:

在head部记入

<META HTTP-EQUIV="Refresh" content="20"> 

其中20为20秒后自动刷新,你可以更改为任意值。

11。网页自动转页

<META HTTP-EQUIV="Refresh" CONTENT="时间(秒);URL=地址"> 

13。返回上一页

<a href=javascript :history.back(1)>『返回上一页』</a>  

14。关闭窗口

<a href=javascript :self.close()>『关闭窗口』</a>

15.oncontextmenu="window.event.returnValue=false"

将彻底屏蔽鼠标右键 :

<table border oncontextmenu=return(false)><td>no</table> 可用于Table 

取消选取、防止复制  :<body onselectstart="return false">

18.onpaste="return false" 不准粘贴

19.oncopy="return false;" oncut="return false;" 防止复制

20. IE地址栏前换成自己的图标

<link rel="Shortcut Icon" href="favicon.ico">  

21.可以在收藏夹中显示出你的图标

<link rel="Bookmark" href="favicon.ico"> 

22. 关闭输入法:

<input style="ime-mode:disabled">

24. 防止被人frame:

<SCRIPT LANGUAGE=JAVASCRIPT><!--   if (top.location != self.location)top.location=self.location;  // --></SCRIPT>

网页将不能被另存为:

<noscript><iframe src=*.html></iframe></noscript>

28.屏蔽功能键Shift,Alt,Ctrl:

<script>   function look(){  if(event.shiftKey)   alert("禁止按Shift键!"); //可以换成ALT CTRL  }   document.onkeydown=look;  </script>

29. 网页不会被缓存 :

<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">  

30.怎样让表单没有凹凸感?

<input type=text style="border:1 solid #000000">   或 <input type=text style="border-left:none; border-right:none; border -top:none; border-bottom: 1 solid #000000"></textarea>

31.不要滚动条

让竖条没有:

<body style="overflow:scroll;overflow-y:hidden">  </body>

让横条没有:

<body style="overflow:scroll;overflow-x:hidden">  </body> 

两个都去:

<body scroll="no"></body>

去掉图片链接点击后,图片周围的虚线?

<a href="#" onFocus="this.blur()"><img src="logo.jpg" border=0></a>  

33.电子邮件处理提交表单

<form name="form1" method="post" action="mailt****@***.com" enctype="text/plain">  <input type=submit>   </form>  

34.在打开的子窗口刷新父窗口的代码里如何写?

window.opener.location.reload()  

35.如何设定打开页面的大小  <body onload="top.resizeTo(300,200);">   打开页面的位置<body onload="top.moveBy(300,200);">

36.在页面中如何加入不是满铺的背景图片,拉动页面时背景图不动

<STYLE>  body   {background-image:url(logo.gif); background-repeat:no-repeat;  background-position:center;background-attachment: fixed}  </STYLE>  

37. 检查一段字符串是否全由数字组成

<script language="Javascript"><!--   function checkNum(str){return str.match(//D/)==null}  alert(checkNum("1232142141"))  alert(checkNum("123214214a1"))  // --></script>  

38. 获得一个窗口的大小

document.body.clientWidth; document.body.clientHeight  

39. 怎么判断是否是字符

if (/[^/x00-/xff]/g.test(s)) alert("含有汉字");  else alert("全是字符");   

40.TEXTAREA自适应文字行数的多少

<textarea rows=1 name=s1 cols=27 onpropertychange="this.style.posHeight=this.scrollHeight">  </textarea>   

43.脚本永不出错

<SCRIPT LANGUAGE="JavaScript">   <!-- Hide function killErrors(){return true;} window.onerror = killErrors; // -->  </SCRIPT>

44.ENTER键可以让光标移到下一个输入框

<input onkeydown="if(event.keyCode==13)event.keyCode=9"> 

46. 各种样式的光标

auto :标准光标  default :标准箭头  hand :手形光标  wait :等待光标  text :I形光标   vertical-text :水平I形光标  no-drop :不可拖动光标  not-allowed :无效光标  help :?帮助光标   all-scroll :三角方向标  move :移动标  crosshair :十字标  e-resize  n-resize  nw-resize  w-resize  s-resize  se-resize  sw-resize

47. 禁止鼠标右键,把Demo的图片全都设为表格的背景,表格的大小与图片的大小一样。这样做看起来是一样的,主要是防止鼠标经过图片时会出现另存的按钮。

禁止鼠标右键:

<script LANGUAGE="JavaScript">  function click() { if (event.button==2)   {alert(呵呵,不好意思,你甭想使用右键下载图片:)); } } document.onmousedown=click </script>

48、在网页的Head部分加入如下代码,这段代码的主要功能是屏蔽PrintScreen键,不断清空剪贴版,防止图片被用文件——另存为菜单另存。

<script language="javascript"> <!--  function testclip(){ try {  if(clipboardData.getData("Text")||clipboardData.getData("HTML")||clipboardData.getData("URL"))  { null; } }  catch(e){  clipboardData.setData("Text","") }  setTimeout("testclip()",500) }  testclip(); //--> </script>

38.页面进入和退出的特效

进入页面

<meta http-equiv="Page-Enter" content="revealTrans(duration=x, transition=y)">

退出页面

<meta http-equiv="Page-Exit" content="revealTrans(duration=x, transition=y)">

这个是页面被载入和调出时的一些特效。

Duration表示特效的持续时间,以秒为单位。Transition表示使用哪种特效,取值为1-23:

0 矩形缩小    1 矩形扩大    2 圆形缩小   3 圆形扩大    4 下到上刷新    5 上到下刷新   6 左到右刷新    7 右到左刷新    8 竖百叶窗   9 横百叶窗    10 错位横百叶窗    11 错位竖百叶窗   12 点扩散  

  13 左右到中间刷新    14 中间到左右刷新   15  中间到上下 

  16 上下到中间    17 右下到左上   18 右上到左下    19 左上到右下    20 左下到右上   21 横条    22 竖条  

  23 以上22种随机选择一种

40.网页是否被检索:

<meta name="ROBOTS" content="属性值"> 

其中属性值有以下一些:

属性值为"all": 文件将被检索,且页上链接可被查询;   属性值为"none": 文件不被检索,而且不查询页上的链接; 

属性值为"index": 文件将被检索;   属性值为"follow": 查询页上的链接; 

属性值为"noindex": 文件不检索,但可被查询链接;   属性值为"nofollow": 文件不被检索,但可查询页上的链接。

在同一页面设置不同文字链接效果的样式.:

<HTML><HEAD><TITLE>如何在同一页面设置不同文字链接效果的样式</TITLE>  <meta http-equiv="Content-Type" content="text/html; charset=gb2312">  <style type="text/css">  <!--   a:hover { font-size: 9pt; color: #FF0000; text-decoration: underline}  a:link { font-size: 9pt; color: #006699; text-decoration: underline}  a:visited { font-size: 9pt; color: #006699; text-decoration: underline}  a:active { font-size: 9pt; color: #FF0000; text-decoration: none}   a.r1:hover { font-size: 9pt; color: #FF0000; text-decoration: underline overline}  a.r1:link { font-size: 9pt; color: #000000; text-decoration: underline overline}  a.r1:visited { font-size: 9pt; color: #99CC00; text-decoration: underline overline}  a.r1:active { font-size: 9pt; color: #000000; text-decoration: underline overline}  -->  </style>  </head>   <body bgcolor="#FFFFFF" text="#000000">  <a href="#">下划线链接 </a>   <p></p>   <a href="#" class="r1">双下划线链接</a>  </BODY>  </HTML> 

补充说明:   a:hover 表示鼠标划过时的样式.  a:link 表示链接的样式.   a:active 表示当前活动连接的样式.   a:visited 表示已经访问过的连接的样式.

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。