日期:2014-05-16  浏览次数:20379 次

maquee代码在html4.0下有效,xhtml1.0就显示不正常
<div id="demo" style="overflow:hidden;height:180;width:210" align="center">
<div id="demo1" align="center">
<table width="210" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
  <td height="5"></td>
  </tr>
  <tr>
  <td height="35"><img src="images/sub1.gif" width="210" height="35" /></td>
  </tr>
  <tr>
  <td height="5"></td>
  </tr>
  <tr>
  <td height="35"><img src="images/sub2.gif" width="210" height="35" /></td>
  </tr>
  <tr>
  <td height="5"></td>
  </tr>
  <tr>
  <td height="35"><img src="images/sub3.gif" width="210" height="35" /></td>
  </tr>
  <tr>
  <td height="5"></td>
  </tr>
  <tr>
  <td height="35"><img src="images/sub4.gif" width="210" height="35" /></td>
  </tr>
<tr>
  <td height="5"></td>
  </tr>
  <tr>
  <td height="35"><img src="images/sub5.gif" width="210" height="35" /></td>
  </tr>
  </table>
</div>
<div id="demo2" align="center"></div>
</div>
<script>
var speed=30
demo2.innerHTML=demo1.innerHTML
function Marquee()
{
if(demo2.offsetTop-demo.scrollTop<=0)
demo.scrollTop-=demo1.offsetHeight
else
{
demo.scrollTop++
}
}

var MyMar
function beginmarquee()
{
  MyMar=setInterval(Marquee,speed)
}

function endmarquee()
{
 clearInterval(MyMar)
}

//var MyMar=setInterval(Marquee,speed)
//demo.onmouseover=function() {clearInterval(MyMar)}
//demo.onmouseout=function() {MyMar=setInterval(Marquee,speed)}
</script>



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 下显示正常,Firefox下也可以。但只要头部用的是

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

就无效了,只有这句demo2.innerHTML=demo1.innerHTML被执行,表格撑成两倍大

------解决方案--------------------
那就是你的代码写的不规范导致的
1、第一行<div id="demo" style="overflow:hidden;height:180;width:210" align="center">改为:<div id="demo" style="overflow:hidden;height:180px;width:210px" align="center">
2、demo,demo1,demo2获取不到ID,你用documentgetElementById分别获取demo,demo1,demo2

你再试下