1 0 0 分,请高手给看看以下代码为什么没有任何反应??好了立即给分。在线,立即给分。
我想实现让div里面的滚动条永远在最下方的效果。代码如下:
<script language= "javascript ">
function showinfo()
{
document.getElementById( "sp ").scrollTop = document.getElementById( "sp ").scrollHeight;}
</script>
<div id= "div1 " style= "width: 400px; height: 300px; background: green;overflow: scroll; " onscroll= " ">
<div style= "width: 300px; height: 600px; background: gray; "> </div>
</div>
<p> </p>
<p> <br>
<span id= "sp "> </span>
<br>
<span id= "sp1 "> </span>
<br>
<span id= "sp2 "> </span>
<br>
<span id= "sp3 "> </span>
<script language= "javascript ">
showinfo();
</script>
可是没有任何反应,我是初学的,请高手给帮助一下。
------解决方案--------------------document.getElementById( "sp ").scrollTop = document.getElementById( "sp ").scrollHeight;
=============> 改为
document.getElementById( "div1 ").scrollTop = document.getElementById( "div1 ").scrollHeight;
------解决方案--------------------呵呵,设一下。setTimeout()吧,这样就能定时动起来了!
------解决方案--------------------赶紧吃饭去吧,身体最重要。
你自己参考一下:
<script language= "javascript ">
function showinfo()
{
document.getElementById( "div1 ").scrollTop = document.getElementById( "div1 ").scrollHeight;
window.scroll(0, document.body.scrollHeight)
}
window.onload = showinfo;
</script>
<div id= "div1 " style= "width: 400px; height: 300px; background: green;overflow: scroll; " onscroll= " ">
<div style= "width: 300px; height: 600px; background: gray; "> </div>
</div>
------解决方案--------------------回在最顶上的 <script language= "javascript "> 后
如:
<script language= "javascript ">
window.onload = showinfo;
function showinfo()
{……
建议先吃饭,原因是你出的错误,都是失误,很可能是饿的眼花了,吃完饭后,去下一个js教程慢慢看看吧