网页常用Javascript

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

你可能感兴趣的:(JavaScript)