日期:2014-05-17  浏览次数:20517 次

js跳转到页头?
javascript或者jquery,在函数内,怎么样通过事件,来跳转到页面的页头。

fucntion top()
{
  ???
}

谢谢。

------解决方案--------------------
引用:
http://blog.sina.com.cn/s/blog_60b35e8301014g68.html

+1
------解决方案--------------------

lastScrollY = 0;
function heartBeat() {
var diffY;
if (document.documentElement && document.documentElement.scrollTop)
diffY = document.documentElement.scrollTop;
else if (document.body)
diffY = document.body.scrollTop;
else
{ /*Netscape stuff*/ }
percent = .1 * (diffY - lastScrollY);
if (percent > 0) percent = Math.ceil(percent);
else percent = Math.floor(percent);
document.getElementById("web_ad").style.top = parseInt(document.getElementById("web_ad").style.top) + percent + "px";
lastScrollY = lastScrollY + percent;
if (lastScrollY > 0) {
document.getElementById("web_ad").style.display = "block";
} else {
document.getElementById("web_ad").style.display = "none";
}
}
suspendcode = "<DIV id=\"web_ad\" style='right:100px;POSITION:absolute;TOP:630px; border:0px solid #ddd;display:none;'><a href='javascript:scroll(0,0)'><img src='/MarkTop.jpg' alt='返回顶部' /></a></div>";
document.write(suspendcode);
window.setInterval("heartBeat()", 1); 


直接把这段放在js就行了,注意把图片MarkTop.jpg替换成你要的
------解决方案--------------------

window.scroll(0,0)