当前位置导航:炫浪网>>网络学院>>网页制作>>JavaScript教程

网页常用Javascript经典代码收集

1.添加到收藏夹 

   HTML代码
<script Language="Javascript"> 
  function bookmarkit() 
  { 
  window.external.addFavorite(’<a href="http://" target="_blank" rel="external">http://</a>你的网址’,’你的网站名称’) 
  } 
  if (document.all)document.write(’<a href="#" onClick="bookmarkit()">加入收藏夹</a>’) 
  </script> 
  [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]

2.让超链接不显示下划线 

   HTML代码
<style type="text/css"> 
  <!- 
  a:link{text-decoration:none} 
  a:hover{text-decoration:none} 
  a:visited{text-decoration:none} 
  -> 
  </style> 
  [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]

3.禁止鼠标右键的动作 

 HTML代码
  <script Language = "Javascript"> 
  function click() { if (event.button==2||event.button==3) 
  { 
  alert(’禁止鼠标右键’); 
  } 
  document.onmousedown=click // --> 
  </script> 
  [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]

4.设置该页为首页 

 HTML代码
  <body bgcolor="#FFFFFF" text="#000000"> 
  <!-- 你的网址:<a href="--" target="_blank" rel="external">http://www.code-123.com/wlbc/asp/list_1.html--</a>> 
  <a   style="cursor:hand" HREF 
  onClick="this.style.behavior=’url(#default#homepage)’; 
  this.setHomePage(’你的网站名称);"><font color="000000" size="2" face="宋体">设为首页</font></a> 
  </body>  </TEXTAREA><br/><INPUT onclick="runEx('temp99357')"  type="button" class="userbutton" value="运行此代码"/> <INPUT onclick="doCopy('temp99357')"  type="button" class="userbutton" value="复制此代码"/> <INPUT onclick="saveCode('temp99357')" type="button" class="userbutton" value="保存此代码">[Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]</div></div><br/><br/>5.让文字不停地滚动&nbsp;&nbsp;<br/><br/><div class="UBBPanel"><EM onClick="copycode(code86103);">复制内容到剪贴板</EM><H5><img src="images/code.gif?http://www.xvna.com" style="margin:0px 2px -3px 0px;border:0" alt="程序代码"/>程序代码</H5><div class="UBBContent" id=code86103>  &lt;MARQUEE&gt;滚动文字&lt;/MARQUEE&gt; </div></div> <br/><br/>6.记录并显示网页的最后修改时间&nbsp;&nbsp;<br/><br/><div class="UBBPanel"><EM onClick="copycode(code77817);">复制内容到剪贴板</EM><H5><img src="images/code.gif?http://www.xvna.com" style="margin:0px 2px -3px 0px;border:0" alt="程序代码"/>程序代码</H5><div class="UBBContent" id=code77817>&nbsp;&nbsp;&nbsp;&nbsp;&lt;script language=Javascript&gt;&nbsp;&nbsp;<br/>  document.write("最后更新时间: " + document.lastModified + "")&nbsp;&nbsp;<br/>  &lt;/script&gt; </div></div> <br/><br/>7.关闭当前窗口&nbsp;&nbsp;<br/><br/><div class="UBBPanel"><EM onClick="copycode(code55791);">复制内容到剪贴板</EM><H5><img src="images/code.gif?http://www.xvna.com" style="margin:0px 2px -3px 0px;border:0" alt="程序代码"/>程序代码</H5><div class="UBBContent" id=code55791>&lt;a href="/"onClick="javascript:window.close();return false;"&gt;关闭窗口&lt;/a&gt;&nbsp;&nbsp;</div></div><br/><br/>8.5秒后关闭当前页&nbsp;&nbsp;<br/><br/><div class="UBBPanel"><div class="UBBTitle"><img src="images/html.gif?http://www.xvna.com" style="margin:0px 2px -3px 0px"> HTML代码</div><div class="UBBContent"><TEXTAREA rows="8" id="temp66245"><script language="Javascript"> 
  <!-- 
  setTimeout(’window.close();’,5000); 
  --> 
  </script>
  [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]

9.2秒后载入指定网页 

   HTML代码
<head> 
  <meta http-equiv="refresh" content="2;URL=http://你的网址"> 
  </head>
  [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]

10.节日倒计时 

   HTML代码
<script Language="Javascript"> 
  var timedate= new Date("December 25,2003"); 
  var times="圣诞节"; 
  var now = new Date(); 
  var date = timedate.getTime() - now.getTime(); 
  var time = Math.floor(date / (1000 * 60 * 60 * 24)); 
  if (time >= 0) 
  document.write("现在离"+times+"还有: "+time +"天")</script>
  [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行] 

11.水中倒影效果 

   HTML代码
<img id="reflect" src="你自己的图片文件名" width="175" height="59"> 
  <script language="Javascript"> 
  function f1() 
  { 
    setInterval("mdiv.filters.wave.phase+=10",100); 
  } 
  if (document.all) 
  { 
    document.write(’<img id=mdiv src="’+document.all.reflect.src+’" 
    style="filter:wave(strength=3,freq=3,phase=0,lightstrength=30) blur() flipv()">’) 
    window.onload=f1 
  } 
  </script>
  [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行] 

12.慢慢变大的窗口 

   HTML代码
<script Language="Javascript"> 
  <!-- 
  var Windowsheight=100 
  var Windowswidth=100 
  var numx=5 
  function openwindow(thelocation){ 
  temploc=thelocation 
  if 
  (!(window.resizeTo&&document.all)&&!(window.resizeTo&&document.getElementById)) 
  { 
    window.open(thelocation) 
    return 
  } 
  windowsize=window.open("","","scrollbars") 
  windowsize.moveTo(0,0) 
  windowsize.resizeTo(100,100) 
  tenumxt() 
  } 
  function tenumxt(){ 
  if (Windowsheight>=screen.availHeight-3) 
    numx=0 
  windowsize.resizeBy(5,numx) 
  Windowsheight+=5 
  Windowswidth+=5 
  if (Windowswidth>=screen.width-5) 
  { 
    windowsize.location=temploc 
    Windowsheight=100 
    Windowswidth=100 
    numx=5 
    return 
  } 
  setTimeout("tenumxt()",50) 
  } 
  //--> 
  </script> 
  <p><a href="javascript:openwindow(<a href="" target="_blank" rel="external">http://www.code-123.com</a>)">进入</a>
  [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行] 

13.改变IE地址栏的IE图标 

  复制内容到剪贴板程序代码
我们要先做一个16*16的icon(图标文件),保存为index.ico。把这个图标文件上传到根目录下并在首页<head></head>之间加上如下代码: 

  <link REL = "Shortcut Icon" href="index.ico">  

 

14.单击按钮打印出当前页 

   HTML代码
<script Language="Javascript"> 
  <!-- Begin 
  if (window.print) { 
  document.write(’<form>’ 
  + ’<input type=button name=print value="打印本页" ’ 
  + ’onClick="javascript:window.print()"></form>’); 
  } 
  // End --> 
  </script> 
  [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]

15.单击按钮‘另存为’当前页 

   HTML代码
<input type="button" name="Button" value="保存本页" 
  onClick="document.all.button.ExecWB(4,1)"> 
  <object id="button" 
  width=0 
  height=0 
  classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"> 
  <embed width="0" height="0"></embed> 
  </object> 
  [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]

16.显示系统当前日期 

   HTML代码
<script language=Javascript> 
  today=new Date(); 
  function date(){ 
  this.length=date.arguments.length 
  for(var i=0;i<this.length;i++) 
  this[i+1]=date.arguments } 
  var d=new date("星期日","星期一","星期二","星期三","星期四","星期五","星期六"); 
  document.write( 
  "<font color=##000000 style=’font-size:9pt;font-family: 宋体’> ", 
  today.getYear(),"年",today.getMonth()+1,"月",today.getDate(),"日", 
  d[today.getDay()+1],"</font>" ); 
  </script>
  [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行] 

17.不同时间段显示不同问候语 

   HTML代码
<script Language="Javascript"> 
  <!-- 
  var text=""; day = new Date( ); time = day.getHours( ); 
  if (( time>=0) && (time < 7 )) 
    text="夜猫子,要注意身体哦! " 
  if (( time >= 7 ) && (time < 12)) 
    text="今天天气……哈哈哈,不去玩吗?" 
  if (( time >= 12) && (time < 14)) 
    text="午休时间哦,朋友一定是不习惯午睡的吧?!" 
  if (( time >=14) && (time < 18)) 
    text="下午茶的时间到了,休息一下吧! " 
  if ((time >= 18) && (time <= 22)) 
    text="您又来了,可别和MM聊太久哦!" 
  if ((time >= 22) && (time < 24)) 
    text="很晚了哦,注意休息呀!" 
  document.write(text) 
  //---> 
  </script>
  [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]

18.不间断音乐

 HTML代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<a href="" target="_blank" rel="external">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</a>">
<html xmlns="<a href="" target="_blank" rel="external">http://www.w3.org/1999/xhtml</a>">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<p>
<input name="src" type="file" id="src" value="E:\music2\fighter.mp3" />
</p>
<p>
<input type="button" name="button" id="button" value="Play" onclick="play(document.getElementById('src').value)" />
<input type="button" name="button2" id="button2" value="Stop" onclick="stop()" />
<input type="button" name="button2" id="button2" value="Pause" onclick="pause()" />
</p>
</body>
</html>
<script>
var player = new ActiveXObject("MediaPlayer.MediaPlayer");
function play(pSrc){
if(pSrc == ""){
   alert("请选择您要播放的音乐!");
   return ;
}
player.Open(pSrc);
}
function stop(){
player.Stop();
}
function pause(){
player.Pause();
}
</script>
  [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]

19.上下左右不间断无缝滚动图片的效果(兼容火狐和IE)

 HTML代码
<html xmlns="<a href="" target="_blank" rel="external">http://www.w3.org/1999/xhtml</a>">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>向上下左右不间断无缝滚动图片的效果(兼容火狐和IE)</title>
</head>
<body>

<!--下面是向上滚动代码-->
<div id=jsweb8_cn_top style=overflow:hidden;height:100;width:90;>
<div id=jsweb8_cn_top1>
<img src="<a href="" target="_blank" rel="external">http://jsweb8.cn/images/logo.gif?http://www.xvna.com</a>">
<img src="<a href="" target="_blank" rel="external">http://jsweb8.cn/images/logo.gif?http://www.xvna.com</a>">
<img src="<a href="" target="_blank" rel="external">http://jsweb8.cn/images/logo.gif?http://www.xvna.com</a>">
<img src="<a href="" target="_blank" rel="external">http://jsweb8.cn/images/logo.gif?http://www.xvna.com</a>">
<img src="<a href="" target="_blank" rel="external">http://jsweb8.cn/images/logo.gif?http://www.xvna.com</a>">
<img src="<a href="" target="_blank" rel="external">http://jsweb8.cn/images/logo.gif?http://www.xvna.com</a>">
<img src="<a href="" target="_blank" rel="external">http://jsweb8.cn/images/logo.gif?http://www.xvna.com</a>">
<img src="<a href="" target="_blank" rel="external">http://jsweb8.cn/images/logo.gif?http://www.xvna.com</a>">
<img src="<a href="" target="_blank" rel="external">http://jsweb8.cn/images/logo.gif?http://www.xvna.com</a>">
</div>
<div id=jsweb8_cn_top2></div>
</div>
<script>
var speed=30
jsweb8_cn_top2.innerHTML=jsweb8_cn_top1.innerHTML //克隆jsweb8_cn_top1为jsweb8_cn_top2
function Marquee1(){
//当滚动至jsweb8_cn_top1与jsweb8_cn_top2交界时
if(jsweb8_cn_top2.offsetTop-jsweb8_cn_top.scrollTop<=0)  
jsweb8_cn_top.scrollTop-=jsweb8_cn_top1.offsetHeight //jsweb8_cn_top跳到最顶端
else{
jsweb8_cn_top.scrollTop++;
}
}
var MyMar1=setInterval(Marquee1,speed)//设置定时器
//鼠标移上时清除定时器达到滚动停止的目的
jsweb8_cn_top.onmouseover=function() {clearInterval(MyMar1)}
//鼠标移开时重设定时器
jsweb8_cn_top.onmouseout=function(){MyMar1=setInterval(Marquee1,speed)}
</script>
<!--向上滚动代码结束-->


<br>
<!--下面是向下滚动代码-->
<div id=jsweb8_cn_bottom style=overflow:hidden;height:100;width:90;>
<div id=jsweb8_cn_bottom1>
<img src="<a href="" target="_blank" rel="external">http://jsweb8.cn/images/logo.gif?http://www.xvna.com</a>">
<img src="<a href="" target="_blank" rel="external">http://jsweb8.cn/images/logo.gif?http://www.xvna.com</a>">
<img src="<a href="" target="_blank" rel="external">http://jsweb8.cn/images/logo.gif?http://www.xvna.com</a>">
<img src="<a href="" target="_blank" rel="external">http://jsweb8.cn/images/logo.gif?http://www.xvna.com</a>">
<img src="<a href="" target="_blank" rel="external">http://jsweb8.cn/images/logo.gif?http://www.xvna.com</a>">
<img src="<a href="" target="_blank" rel="external">http://jsweb8.cn/images/logo.gif?http://www.xvna.com</a>">
<img src="<a href="" target="_blank" rel="external">http://jsweb8.cn/images/logo.gif?http://www.xvna.com</a>">
<img src="<a href="" target="_blank" rel="external">http://jsweb8.cn/images/logo.gif?http://www.xvna.com</a>">
<img src="<a href="" target="_blank" rel="external">http://jsweb8.cn/images/logo.gif?http://www.xvna.com</a>">
</div>
<div id=jsweb8_cn_bottom2></div>
</div>
<script>
var speed=30
jsweb8_cn_bottom2.innerHTML=jsweb8_cn_bottom1.innerHTML
jsweb8_cn_bottom.scrollTop=jsweb8_cn_bottom.scrollHeight
function Marquee2(){
if(jsweb8_cn_bottom1.offsetTop-jsweb8_cn_bottom.scrollTop>=0)
jsweb8_cn_bottom.scrollTop+=jsweb8_cn_bottom2.offsetHeight
else{
jsweb8_cn_bottom.scrollTop--
}
}
var MyMar2=setInterval(Marquee2,speed)
jsweb8_cn_bottom.onmouseover=function() {clearInterval(MyMar2)}
jsweb8_cn_bottom.onmouseout=function() {MyMar2=setInterval(Marquee2,speed)}
</script>
<!--向下滚动代码结束-->


<br>
<!--下面是向左滚动代码-->
<div id="jsweb8_cn_left" style="overflow:hidden;width:500px;">
<table cellpadding="0" cellspacing="0" border="0">
<tr><td id="jsweb8_cn_left1" valign="top" align="center">
<table cellpadding="2" cellspacing="0" border="0">
<tr align="center">
<td><img src="<a href="" target="_blank" rel="external">http://jsweb8.cn/images/logo.gif?http://www.xvna.com</a>"></td>
<td><img src="<a href="" target="_blank" rel="external">http://jsweb8.cn/images/logo.gif?http://www.xvna.com</a>"></td>
<td><img src="<a href="" target="_blank" rel="external">http://jsweb8.cn/images/logo.gif?http://www.xvna.com</a>"></td>
<td><img src="<a href="" target="_blank" rel="external">http://jsweb8.cn/images/logo.gif?http://www.xvna.com</a>"></td>
<td><img src="<a href="" target="_blank" rel="external">http://jsweb8.cn/images/logo.gif?http://www.xvna.com</a>"></td>
<td><img src="<a href="" target="_blank" rel="external">http://jsweb8.cn/images/logo.gif?http://www.xvna.com</a>"></td>
<td><img src="<a href="" target="_blank" rel="external">http://jsweb8.cn/images/logo.gif?http://www.xvna.com</a>"></td>
</tr>
</table>
</td>
<td id="jsweb8_cn_left2" valign="top"></td>
</tr>
</table>
</div>
<script>
var speed=30//速度数值越大速度越慢
jsweb8_cn_left2.innerHTML=jsweb8_cn_left1.innerHTML
function Marquee3(){
if(jsweb8_cn_left2.offsetWidth-jsweb8_cn_left.scrollLeft<=0)
jsweb8_cn_left.scrollLeft-=jsweb8_cn_left1.offsetWidth
else{
jsweb8_cn_left.scrollLeft++
}
}
var MyMar3=setInterval(Marquee3,speed)
jsweb8_cn_left.onmouseover=function() {clearInterval(MyMar3)}
jsweb8_cn_left.onmouseout=function() {MyMar3=setInterval(Marquee3,speed)}
</script>
<!--向左滚动代码结束-->


<br>
<!--下面是向右滚动代码-->
<div id="jsweb8_cn_right" style="overflow:hidden;width:500px;">
<table cellpadding="0" cellspacing="0" border="0">
<tr><td id="jsweb8_cn_right1" valign="top" align="center">
<table cellpadding="2" cellspacing="0" border="0">
<tr align="center">
<td><img src="<a href="" target="_blank" rel="external">http://jsweb8.cn/images/logo.gif?http://www.xvna.com</a>"></td>
<td><img src="<a href="" target="_blank" rel="external">http://jsweb8.cn/images/logo.gif?http://www.xvna.com</a>"></td>
<td><img src="<a href="" target="_blank" rel="external">http://jsweb8.cn/images/logo.gif?http://www.xvna.com</a>"></td>
<td><img src="<a href="" target="_blank" rel="external">http://jsweb8.cn/images/logo.gif?http://www.xvna.com</a>"></td>
<td><img src="<a href="" target="_blank" rel="external">http://jsweb8.cn/images/logo.gif?http://www.xvna.com</a>"></td>
</tr>
</table>
</td>
<td id="jsweb8_cn_right2" valign="top"></td>
</tr>
</table>
</div>
<script>
var speed=30//速度数值越大速度越慢
jsweb8_cn_right2.innerHTML=jsweb8_cn_right1.innerHTML
function Marquee4(){
if(jsweb8_cn_right.scrollLeft<=0)
jsweb8_cn_right.scrollLeft+=jsweb8_cn_right2.offsetWidth
else{
jsweb8_cn_right.scrollLeft--
}
}
var MyMar4=setInterval(Marquee4,speed)
jsweb8_cn_right.onmouseover=function() {clearInterval(MyMar4)}
jsweb8_cn_right.onmouseout=function() {MyMar4=setInterval(Marquee4,speed)}
</script>
<!--向右滚动代码结束-->

</body>
</html>

  [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]

20.不间断向左滚动

 HTML代码
<div id=demo style=overflow:hidden;height:139;width:232;background:#f4f4f4;color:#ffffff><table align=left cellpadding=0 cellspace=0 border=0><tr><td id=demo1 valign=top><img src="<a href="" target="_blank" rel="external">http://www.makewing.com/lanren/jscode/js-0063/images/01.jpg?http://www.xvna.com</a>"><img src="<a href="" target="_blank" rel="external">http://www.makewing.com/lanren/jscode/js-0063/images/02.jpg?http://www.xvna.com</a>"><img src="<a href="" target="_blank" rel="external">http://www.makewing.com/lanren/jscode/js-0063/images/03.jpg?http://www.xvna.com</a>"><img src="<a href="" target="_blank" rel="external">http://www.makewing.com/lanren/jscode/js-0063/images/04.jpg?http://www.xvna.com</a>"><img src="<a href="" target="_blank" rel="external">http://www.makewing.com/lanren/jscode/js-0063/images/05.jpg?http://www.xvna.com</a>"></td><td id=demo2 valign=top></td></tr></table></div>
<script>
var speed=30
demo2.innerHTML=demo1.innerHTML
function Marquee(){
if(demo2.offsetWidth-demo.scrollLeft<=0)
demo.scrollLeft-=demo1.offsetWidth
else{
demo.scrollLeft++
}
}
var MyMar=setInterval(Marquee,speed)
demo.onmouseover=function() {clearInterval(MyMar)}
demo.onmouseout=function() {MyMar=setInterval(Marquee,speed)}
</script>
  [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]


21.不间断向右滚动

 HTML代码
<div id=demo style=overflow:hidden;height:139;width:232;background:#f4f4f4;color:#ffffff><table align=left cellpadding=0 cellspace=0 border=0><tr><td id=demo1 valign=top><img src="<a href="" target="_blank" rel="external">http://www.makewing.com/lanren/jscode/js-0063/images/01.jpg?http://www.xvna.com</a>"><img src="<a href="" target="_blank" rel="external">http://www.makewing.com/lanren/jscode/js-0063/images/02.jpg?http://www.xvna.com</a>"><img src="<a href="" target="_blank" rel="external">http://www.makewing.com/lanren/jscode/js-0063/images/03.jpg?http://www.xvna.com</a>"><img src="<a href="" target="_blank" rel="external">http://www.makewing.com/lanren/jscode/js-0063/images/04.jpg?http://www.xvna.com</a>"><img src="<a href="" target="_blank" rel="external">http://www.makewing.com/lanren/jscode/js-0063/images/05.jpg?http://www.xvna.com</a>"></td><td id=demo2 valign=top></td></tr></table></div>
<script>
var speed=30
demo2.innerHTML=demo1.innerHTML
demo.scrollLeft=demo.scrollWidth
function Marquee(){
if(demo.scrollLeft<=0)
demo.scrollLeft+=demo2.offsetWidth
else{
demo.scrollLeft--
}
}
var MyMar=setInterval(Marquee,speed)
demo.onmouseover=function() {clearInterval(MyMar)}
demo.onmouseout=function() {MyMar=setInterval(Marquee,speed)}
</script>
  [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]


连续滚动或不间断滚动代码(各种滚动方式)兼容IE和FireFox Opera 傲游 等浏览器的间隔滚动代码

由左向右方法一:

 HTML代码
<div id=demo style="OVERFLOW: hidden; WIDTH: 980px; height: 80px;align: center">
<table cellspacing="0" cellpadding="0" align="center"
border="0">
    <tbody>
      <tr>
        <td id="marquePic1" valign="top">
 
<table width="980" height="80" border="0" cellpadding="0" cellspacing="0">
<tr>
    <td width="148" height="60" bgcolor="#F2F6FB"><a href="#" target="_blank"><img src="/img/bottom_ad01.gif?http://www.xvna.com" border="0"></a></td>
      <td width="148" height="60" bgcolor="#F2F6FB"><a href="#" target="_blank"><img src="/img/bottom_ad02.gif?http://www.xvna.com" border="0"></a></td>
      <td width="148" height="60" bgcolor="#F2F6FB"><a href="#" target="_blank"><img src="/img/bottom_ad03.gif?http://www.xvna.com" border="0"></a></td>
      <td width="148" height="60" bgcolor="#F2F6FB"><a href="#" target="_blank"><img src="/img/bottom_ad04.gif?http://www.xvna.com" border="0"></a></td>
      <td width="148" height="60" bgcolor="#F2F6FB"><a href="#" target="_blank"><img src="/img/bottom_ad05.gif?http://www.xvna.com" border="0"></a></td>
   <td width="148" height="60" bgcolor="#F2F6FB"><a href="/info/about.asp?id=4" target="_blank"><img src="/img/bottom_ad06.gif?http://www.xvna.com" border="0"></a></td>
</tr>

</table> 
 
   </td>
        <td id="marquePic2" valign="top"></td>
      </tr>
    </tbody>
</table>
</div>
<script type=text/javascript>
var speed=80 <!--值越大速度越慢 -->
marquePic2.innerHTML=marquePic1.innerHTML
function Marquee(){
if(demo.scrollLeft>=marquePic1.scrollWidth){
demo.scrollLeft=0
}else{
demo.scrollLeft++
}}
var MyMar=setInterval(Marquee,speed)
demo.onmouseover=function() {clearInterval(MyMar)}
demo.onmouseout=function() {MyMar=setInterval(Marquee,speed)}
</script>
  [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]

由下向上方法一:

 HTML代码
<table width="100%" border="0" cellspacing="2" cellpadding="2">
<tr> <td align="center"> <table width="150" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="194" style="padding-top:8px" valign="top">
<DIV id=rolllinkk style="OVERFLOW: hidden; WIDTH: 145px; HEIGHT: 200px">
<DIV id=rolllinkk1>

<!-- 下面是你要显示的内容 -->
<table width="100%" border="0" cellspacing="2" cellpadding="2">

<tr> <td align="center">最牛交通工具 </td> </tr>

<tr> <td align="center">最牛交通工具 </td> </tr>

<tr> <td align="center">最牛交通工具 </td> </tr>

<tr> <td align="center">最牛交通工具 </td> </tr>

<tr> <td align="center">最牛交通工具 </td> </tr>

<tr> <td align="center">最牛交通工具 </td> </tr>

<tr> <td align="center">最牛交通工具 </td> </tr>

<tr> <td align="center">最牛交通工具 </td> </tr>

<tr> <td align="center">最牛交通工具 </td> </tr>

<tr> <td align="center">最牛交通工具 </td> </tr>

<tr> <td align="center">最牛交通工具 </td> </tr>

</table>
    <!-- 显示的内容结束! -->

                  <DIV align=center> </DIV> </DIV>
                  <DIV id=rolllinkk2>

                  <DIV align=center> </DIV> </DIV> </DIV>
                  <SCRIPT>
var rollspeed=30
rolllinkk2.innerHTML=rolllinkk1.innerHTML //
function Marquee1(){
if(rolllinkk2.offsetTop-rolllinkk.scrollTop <=0) //
rolllinkk.scrollTop-=rolllinkk1.offsetHeight //
else{
rolllinkk.scrollTop++
}
}
var MyMar1=setInterval(Marquee1,rollspeed) //
rolllinkk.onmouseover=function() {clearInterval(MyMar1)}//
rolllinkk.onmouseout=function() {MyMar1=setInterval(Marquee1,rollspeed)}//
</SCRIPT>
</td>

</tr>
</table>
</td> </tr>

</table>
  [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]

不间断多行滚动,可控制按钮

 HTML代码
<script language="JavaScript" defer>
//qswh's original and modifid by windy_sk <> 20040120
function reportError(msg,url,line) {
var str = "You have found an error as below: \n\n";
str += "Err: " + msg + " on line: " + line;
alert(str);
return true;
}
window.onerror = reportError;
var obj_marquee = document.getElementById("marquee");
var repeat = null;
var marquee_spd = 50;
function marquee_init() {
var obj_unit = obj_marquee.firstChild;
var marquee_high = parseInt(obj_marquee.style.height);
var marquee_wide = parseInt(obj_marquee.style.width);
var unit_high = obj_unit.offsetHeight;
var unit_wide = obj_unit.offsetWidth;
var m = 0, n = 0, i = 0;
var tmp = null;

m = Math.ceil(marquee_wide / unit_wide);
n = Math.ceil(marquee_high / unit_high);
obj_unit.style.width = marquee_wide * (m+1);
obj_unit.rows[0].cells[0].style.width = obj_marquee.style.width;

for(i=0; i<m; i++) {
   tmp = obj_unit.rows[0].insertCell(-1);
   tmp.innerHTML = obj_unit.rows[0].cells[0].innerHTML;
   tmp.style.width = marquee_wide;
   tmp = null;
}
for(i=0; i<n; i++) {
   obj_marquee.appendChild(obj_unit.cloneNode(true));
}
return;
}
function marquee_show(direction) {
switch(direction) {
   case "up":
    if(obj_marquee.scrollTop >= obj_marquee.children[1].offsetTop) {
     obj_marquee.scrollTop -= obj_marquee.firstChild.offsetHeight;
    } else {
     obj_marquee.scrollTop++;
    }
    break;
   case "down":
    if(obj_marquee.scrollTop <= 0) {
     obj_marquee.scrollTop += obj_marquee.firstChild.offsetHeight;
    } else {
     obj_marquee.scrollTop--;
    }
    break;
   case "left":
    if(obj_marquee.scrollLeft >= obj_marquee.firstChild.rows[0].cells[0].offsetWidth) {
     obj_marquee.scrollLeft -= obj_marquee.firstChild.rows[0].cells[0].offsetWidth;
    } else {
     obj_marquee.scrollLeft++;
    }
    break;
   case "right":
    if(obj_marquee.scrollLeft <= 0) {
     obj_marquee.scrollLeft += obj_marquee.firstChild.rows[0].cells[0].offsetWidth;
    } else {
     obj_marquee.scrollLeft--;
    }
    break;
   default:
    break;
}
return;
}
function marquee_doit() {
var direction = "";
direction = obj_marquee.getAttribute("direction");
if(direction != null) marquee_show(direction);
direction = obj_marquee.getAttribute("direction2");
if(direction != null) marquee_show(direction);
return;
}
marquee_init();
repeat = setInterval("marquee_doit()",marquee_spd);
marquee.onmouseover = function() {clearInterval(repeat);}
marquee.onmouseout = function() {repeat=setInterval("marquee_doit()",marquee_spd);}
</script>
<table style="border:1px black solid;"><tr><td>
<div id="marquee" direction="up" style="overflow:hidden;height:200px;width:250px">
<table style="border:0px;padding:0px;"><tr><td>
    <!-- Marquee Body Head -->
    <a href="#" target="_blank">经典论坛</a><br>
    <a href="#" target="_blank">163.com</a><br>
    <a href="#" target="_blank">21cn.com</a><br>
    <a href="#" target="_blank">Happy new year</a>
    <!-- Marquee Body Bottom -->
</td></tr></table>
</div>
</td></tr></table>
Direction1:
<input type="button" value="↑" onclick="obj_marquee.direction='up'">
<input type="button" value="↓" onclick="obj_marquee.direction='down'">
<input type="button" value="←" onclick="obj_marquee.direction='left'">
<input type="button" value="→" onclick="obj_marquee.direction='right'">
<input type="button" value=" X " onclick="obj_marquee.direction=''"> <br>
Direction2:
<input type="button" value="↑" onclick="obj_marquee.direction2='up'">
<input type="button" value="↓" onclick="obj_marquee.direction2='down'">
<input type="button" value="←" onclick="obj_marquee.direction2='left'">
<input type="button" value="→" onclick="obj_marquee.direction2='right'">
<input type="button" value=" X " onclick="obj_marquee.direction2=''">
  [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]

相关内容
赞助商链接