为什么这个总是找不到对象?

虫二二 2009-12-30 02:47:15
[code=JavaScript]
<head>
<script type="text/javascript">
var speed=30;

var layer=document.getElementById("layer");
var layer1=document.getElementById("layer1");
var layer2=document.getElementById("layer2");

alert(layer2);
layer2.innerHTML=layer1.innerHTML;

//滑动函数
var Marquee=function(){
//当滚动至colee1与colee2交界时
if(layer2.offsetTop-layer.scrollTop<=0){
leyer.scrollTop-=layer1.offsetHeight;
}
else{
layer.scrollTop++;
}
}
</script>
</head>
<body>
<div id="layer" style="overflow:hidden;width:280px;height:180px">
<div id="layer1">
<p><img alt="" src="../../Images/1.jpg" /></p>
<p><img alt="" src="../../Images/2.jpg" /></p>
<p><img alt="" src="../../Images/3.jpg" /></p>
<p><img alt="" src="../../Images/4.jpg" /></p>
<p><img alt="" src="../../Images/5.jpg" /></p>
</div>
<div id="layer2">layer2</div>
</div>
</body>
[/code]
...全文
70 4 打赏 收藏 举报
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
虫二二 2009-12-30
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 lihui_shine 的回复:]
将JS放在HTML代码后面
HTML code<head></head><body><divid="layer" style="overflow:hidden;width:280px;height:180px"><divid="layer1"><p><imgalt="" src="../../Images/1.jpg"/></p><p><imgalt="" src="../../Images/2.jpg"/></p><p><imgalt="" src="../../Images/3.jpg"/></p><p><imgalt="" src="../../Images/4.jpg"/></p><p><imgalt="" src="../../Images/5.jpg"/></p></div><divid="layer2">layer2</div></div><scripttype="text/javascript">var speed=30;var layer=document.getElementById("layer");var layer1=document.getElementById("layer1");var layer2=document.getElementById("layer2");

alert(layer2);
layer2.innerHTML=layer1.innerHTML;//滑动函数var Marquee=function(){//当滚动至colee1与colee2交界时if(layer2.offsetTop-layer.scrollTop<=0){
leyer.scrollTop-=layer1.offsetHeight;
}else{
layer.scrollTop++;
}
}</script></body>
[/Quote]

呵呵,的确,我在还没写完就遇到了这个问题,汗死了
浪尖赏花 2009-12-30
  • 打赏
  • 举报
回复
LZ的代码好象还差点嘛^_^
<head> 

</head>
<body>
<div id="layer" style="overflow:hidden;width:280px;height:180px">
<div id="layer1">
<p> <img alt="" src="../../Images/1.jpg" /> </p>
<p> <img alt="" src="../../Images/2.jpg" /> </p>
<p> <img alt="" src="../../Images/3.jpg" /> </p>
<p> <img alt="" src="../../Images/4.jpg" /> </p>
<p> <img alt="" src="../../Images/5.jpg" /> </p>
</div>
<div id="layer2">layer2 </div>
</div>
<script type="text/javascript">
var speed=30;

var layer=document.getElementById("layer");
var layer1=document.getElementById("layer1");
var layer2=document.getElementById("layer2");

layer2.innerHTML=layer1.innerHTML;

//滑动函数
var Marquee=function(){
//当滚动至colee1与colee2交界时
if(layer2.offsetTop-layer.scrollTop <=0){
layer.scrollTop-=layer1.offsetHeight;
}
else{
layer.scrollTop++;
}
}
var MyMar=setInterval(Marquee,speed);
layer.onmouseover=function() {clearInterval(MyMar);};//鼠标移上时清除定时器达到滚动停止的目的
layer.onmouseout=function() {MyMar=setInterval(Marquee,speed);};//鼠标移开时重设定时器
</script>
</body>
浪尖赏花 2009-12-30
  • 打赏
  • 举报
回复
将JS放在HTML代码后面
<head> 

</head>
<body>
<div id="layer" style="overflow:hidden;width:280px;height:180px">
<div id="layer1">
<p> <img alt="" src="../../Images/1.jpg" /> </p>
<p> <img alt="" src="../../Images/2.jpg" /> </p>
<p> <img alt="" src="../../Images/3.jpg" /> </p>
<p> <img alt="" src="../../Images/4.jpg" /> </p>
<p> <img alt="" src="../../Images/5.jpg" /> </p>
</div>
<div id="layer2">layer2 </div>
</div>
<script type="text/javascript">
var speed=30;

var layer=document.getElementById("layer");
var layer1=document.getElementById("layer1");
var layer2=document.getElementById("layer2");

alert(layer2);
layer2.innerHTML=layer1.innerHTML;

//滑动函数
var Marquee=function(){
//当滚动至colee1与colee2交界时
if(layer2.offsetTop-layer.scrollTop <=0){
leyer.scrollTop-=layer1.offsetHeight;
}
else{
layer.scrollTop++;
}
}
</script>
</body>
虫二二 2009-12-30
  • 打赏
  • 举报
回复

<head>
<script type="text/javascript">
var speed=30;

var layer=document.getElementById("layer");
var layer1=document.getElementById("layer1");
var layer2=document.getElementById("layer2");

alert(layer2);
layer2.innerHTML=layer1.innerHTML;

//滑动函数
var Marquee=function(){
//当滚动至colee1与colee2交界时
if(layer2.offsetTop-layer.scrollTop<=0){
leyer.scrollTop-=layer1.offsetHeight;
}
else{
layer.scrollTop++;
}
}
</script>
</head>
<body>
<div id="layer" style="overflow:hidden;width:280px;height:180px">
<div id="layer1">
<p><img alt="" src="../../Images/1.jpg" /></p>
<p><img alt="" src="../../Images/2.jpg" /></p>
<p><img alt="" src="../../Images/3.jpg" /></p>
<p><img alt="" src="../../Images/4.jpg" /></p>
<p><img alt="" src="../../Images/5.jpg" /></p>
</div>
<div id="layer2">layer2</div>
</div>
</body>
相关推荐
发帖
JavaScript

8.7w+

社区成员

Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
帖子事件
创建了帖子
2009-12-30 02:47
社区公告
暂无公告