首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Ajax >

为什么小弟我的SCROLLTOP()不能用

2012-10-13 
为什么我的SCROLLTOP()不能用HTML codehtmlscript typetext/javascript srchttp://ajax.googleapi

为什么我的SCROLLTOP()不能用

HTML code
<html><script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script><script type="text/javascript">function clickShow(obj){    document.getElementById('myiframe').src=obj;}function goUp(){    document.getElementById('myiframe').scrollTop=40;    alert(document.getElementById('myiframe').scrollTop);}$(document).ready(function() {    $('#myiframe').scrollTop(30);    //alert($('#myiframe').scrollTop());    //goUp();});</script><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Insert title here</title></head><body><iframe src="mainWeb.html" height="30"></iframe></body></html>


无论是$('#myiframe').scrollTop()还是document.getElementById('myiframe').scrollTop, 返回都是0.求解 谢谢.

[解决办法]
CSS code
<script type="text/javascript">function clickShow(obj){document.getElementById('myiframe').src=obj;}function goUp(){document.getElementById('myiframe').scrollTop=40;//下面没有id,所以才找不对iframealert(document.getElementById('myiframe').scrollTop);}$(document).ready(function() {$('#myiframe').scrollTop(30);//alert($('#myiframe').scrollTop());//也可以alert($("iframe").scrollTop());这样可以不用id  //goUp();});</script><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Insert title here</title></head><body><iframe src="mainWeb.html" height="30" id="myiframe"></iframe>//没有设置id</body></html>
[解决办法]
iframe没有scrollTop的,他是框架,你要获取的是iframe中的body的scrollTop

JScript code
$(document).ready(function() {    $('#myiframe').contents().find('body').scrollTop(100)    //alert($('#myiframe').scrollTop());    //goUp();}); 

热点排行