首页 新闻 会员 周边

再问一个js问题

0
悬赏园豆:10 [已关闭问题]

<!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" >
<HTML>
<head>
<title>右侧随滚动条浮动广告</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
</head>
<body>
<!--浮动广告代码开始-->
<div id="divMenu" style="position: absolute; visibility:visible; left:814px; top:0px; width:200px; ">
  <table height="400" cellspacing="0" cellpadding="0" width="100%" border="0">
    <tbody>
      <tr>
        <td><iframe src="images/ad.htm" frameborder="0" width="180"
      height="470" allowtransparency="allowTransparency"></iframe></td>
      </tr>
    </tbody>
  </table>
</div>
<script type="text/javascript">
<!--

function moveRightEdge()
{
 var yMenuFrom, yMenuTo, yOffset, timeoutNextCheck;
 yMenuFrom   = parseInt (document.getElementById('divMenu').style.top, 0);
 yMenuTo     = document.body.scrollTop + 40;
 
 timeoutNextCheck = 500;
 if (yMenuFrom != yMenuTo)
 {
  yOffset = Math.ceil(Math.abs(yMenuTo - yMenuFrom) / 20);
  if (yMenuTo < yMenuFrom)
  {yOffset = -yOffset;}
  document.getElementById('divMenu').style.top = parseInt (document.getElementById('divMenu').style.top, 0) + yOffset;
  timeoutNextCheck = 10;
 }
 setTimeout ("moveRightEdge()", timeoutNextCheck);
}

 document.getElementById('divMenu').style.top = document.body.scrollTop + 200;
 document.getElementById('divMenu').style.visibility = "visible";
 moveRightEdge();
//-->
</script>
<!--浮动广告代码结束-->
<div style="height:2000px;"></div>
</body>
</html>
-----------------------

上面这段代码,把<!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" >

删除就正常,请问怎么回事?在firefox里面看,提示top有问题。搞不懂

红尘中迷茫的主页 红尘中迷茫 | 初学一级 | 园豆:60
提问于:2008-10-30 08:43
< >
分享
其他回答(3)
0

将前两行删除就正常 说明楼主写的代码不规范 比如你这里有大写的标签,这是不对的 建议楼主去http://validator.w3.org/#validate_by_input这个页面验证一下代码

张荣华 | 园豆:2020 (老鸟四级) | 2008-10-30 10:00
0

代码不符号你定义的标准。有时候用网上搜来的特效等。也遇到过同样的问题。把JS,CSS块再重构一遍。

Astar | 园豆:40805 (高人七级) | 2008-10-30 14:53
0

那是当然firefox和ie不兼容,你可以判断一下浏览器,然后执行

<%if (Request.Browser.Browser.Equals("IE"))
  {%>
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<% }%>

Geeks | 园豆:560 (小虾三级) | 2008-10-30 15:00
0

你给top设置属性的时候需要指定单位。

例如:

你的代码:

document.getElementById('divMenu').style.top = document.body.scrollTop + 200;

应该修改为:

document.getElementById('divMenu').style.top = document.body.scrollTop + 200 + "px";

5yplan | 园豆:1330 (小虾三级) | 2008-11-04 00:33
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册