网页常用Javascript

来源:互联网 发布:数据中的实时计算 编辑:程序博客网 时间:2024/04/20 04:30
  1. 1.让文字不停地滚动 
  2.   <MARQUEE>滚动文字</MARQUEE> 
  3. 2.记录并显示网页的最后修改时间 
  4.   <script language=Javascript> 
  5.   document.write("最后更新时间: " + document.lastModified + ""
  6.   </script> 
  7. 3.关闭当前窗口 
  8.   <a href="/"onClick="javascript:window.close();return false;">关闭窗口</a> 
  9. 4.5秒后关闭当前页 
  10.   <script language="Javascript"> 
  11.   <!-- 
  12.   setTimeout('window.close();',5000); 
  13.   --> 
  14.   </script> 
  15. 5.2秒后载入指定网页 
  16.   <head> 
  17.   <meta http-equiv="refresh" content="2;URL=http://你的网址"> 
  18.   </head> 
  19. 6.添加到收藏夹 
  20.   <script Language="Javascript"> 
  21.   function bookmarkit() 
  22.   { 
  23.   window.external.addFavorite('http://你的网址','你的网站名称'
  24.   } 
  25.   if (document.all)document.write('<a href="#" onClick="bookmarkit()">加入收藏夹</a>'
  26.   </script> 
  27. 7.让超链接不显示下划线 
  28.   <style type="text/css"> 
  29.   <!- 
  30.   a:link{text-decoration:none} 
  31.   a:hover{text-decoration:none} 
  32.   a:visited{text-decoration:none} 
  33.   -> 
  34.   </style> 
  35. 8.禁止鼠标右键的动作 
  36.   <script Language = "Javascript"> 
  37.   function click() { if (event.button==2||event.button==3) 
  38.   { 
  39.   alert('禁止鼠标右键'); 
  40.   } 
  41.   document.onmousedown=click // --> 
  42.   </script> 
  43. 9.设置该页为首页 
  44.   <body bgcolor="#FFFFFF" text="#000000"> 
  45.   <!-- 网址:http://你的网址--> 
  46.   <a class="chlnk" style="cursor:hand" HREF 
  47.   onClick="this.style.behavior='url(#default#homepage)'
  48.   this.setHomePage('你的网站名称);"><font color="000000" size="2" face="宋体">设为首页</font></a> 
  49.   </body> 
  50. 10.节日倒计时 
  51.   <script Language="Javascript"> 
  52.   var timedate= new Date("December 25,2003"); 
  53.   var times="圣诞节"
  54.   var now = new Date(); 
  55.   var date = timedate.getTime() - now.getTime(); 
  56.   var time = Math.floor(date / (1000 * 60 * 60 * 24)); 
  57.   if (time >= 0) 
  58.   document.write("现在离"+times+"还有: "+time +"天")</script> 
  59. 11.单击按钮打印出当前页 
  60.   <script Language="Javascript"> 
  61.   <!-- Begin 
  62.   if (window.print) { 
  63.   document.write('<form>' 
  64.   + '<input type=button name=print value="打印本页" ' 
  65.   + 'onClick="javascript:window.print()"></form>'); 
  66.   } 
  67.   // End --> 
  68.   </script> 
  69. 12.单击按钮‘另存为’当前页 
  70.   <input type="button" name="Button" value="保存本页" 
  71.   onClick="document.all.button.ExecWB(4,1)"> 
  72.   <object id="button" 
  73.   width=0 
  74.   height=0 
  75.   classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"> 
  76.   <embed width="0" height="0"></embed> 
  77.   </object> 
  78. 13.显示系统当前日期 
  79.   <script language=Javascript> 
  80.   today=new Date(); 
  81.   function date(){ 
  82.   this.length=date.arguments.length 
  83.   for(var i=0;i<this.length;i++) 
  84.   this[i+1]=date.arguments } 
  85.   var d=new date("星期日","星期一","星期二","星期三","星期四","星期五","星期六"); 
  86.   document.write( 
  87.   "<font color=##000000 style='font-size:9pt;font-family: 宋体'> "
  88.   today.getYear(),"年",today.getMonth()+1,"月",today.getDate(),"日"
  89.   d[today.getDay()+1],"</font>" ); 
  90.   </script> 
  91. 14.不同时间段显示不同问候语 
  92.   <script Language="Javascript"> 
  93.   <!-- 
  94.   var text=""; day = new Date( ); time = day.getHours( ); 
  95.   if (( time>=0) && (time < 7 )) 
  96.     text="夜猫子,要注意身体哦! " 
  97.   if (( time >= 7 ) && (time < 12)) 
  98.     text="今天天气……哈哈哈,不去玩吗?" 
  99.   if (( time >= 12) && (time < 14)) 
  100.     text="午休时间哦,朋友一定是不习惯午睡的吧?!" 
  101.   if (( time >=14) && (time < 18)) 
  102.     text="下午茶的时间到了,休息一下吧! " 
  103.   if ((time >= 18) && (time <= 22)) 
  104.     text="您又来了,可别和MM聊太久哦!" 
  105.   if ((time >= 22) && (time < 24)) 
  106.     text="很晚了哦,注意休息呀!" 
  107.   document.write(text) 
  108.   //---> 
  109.   </script> 
  110. 15.水中倒影效果 
  111.   <img id="reflect" src="你自己的图片文件名" width="175" height="59"> 
  112.   <script language="Javascript"> 
  113.   function f1() 
  114.   { 
  115.     setInterval("mdiv.filters.wave.phase+=10",100); 
  116.   } 
  117.   if (document.all) 
  118.   { 
  119.     document.write('<img id=mdiv src="'+document.all.reflect.src+'" 
  120.     style="filter:wave(strength=3,freq=3,phase=0,lightstrength=30) blur() flipv()">') 
  121.     window.onload=f1 
  122.   } 
  123.   </script> 
  124. 16.慢慢变大的窗口 
  125.   <script Language="Javascript"> 
  126.   <!-- 
  127.   var Windowsheight=100 
  128.   var Windowswidth=100 
  129.   var numx=5 
  130.   function openwindow(thelocation){ 
  131.   temploc=thelocation 
  132.   if 
  133.   (!(window.resizeTo&&document.all)&&!(window.resizeTo&&document.getElementById)) 
  134.   { 
  135.     window.open(thelocation) 
  136.     return 
  137.   } 
  138.   windowsize=window.open("","","scrollbars"
  139.   windowsize.moveTo(0,0) 
  140.   windowsize.resizeTo(100,100) 
  141.   tenumxt() 
  142.   } 
  143.   function tenumxt(){ 
  144.   if (Windowsheight>=screen.availHeight-3) 
  145.     numx=0 
  146.   windowsize.resizeBy(5,numx) 
  147.   Windowsheight+=5 
  148.   Windowswidth+=5 
  149.   if (Windowswidth>=screen.width-5) 
  150.   { 
  151.     windowsize.location=temploc 
  152.     Windowsheight=100 
  153.     Windowswidth=100 
  154.     numx=5 
  155.     return 
  156.   } 
  157.   setTimeout("tenumxt()",50) 
  158.   } 
  159.   //--> 
  160.   </script> 
  161.   <p><a href="javascript:openwindow(http://www.3ydesign.com)">进入</a> 
  162. 17.改变IE地址栏的IE图标 
  163.   我们要先做一个16*16的icon(图标文件),保存为index.ico。把这个图标文件上传到根目录下并在首页<head></head>之间加上如下代码: 
  164.   <link REL = "Shortcut Icon" href="index.ico">