javascript 自动滚动页面到 HTML 的特定元素
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18979344/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Auto scroll of page to specific element of HTML
提问by chaman shareef
Hi I have length jsp page and at the bottom of the page I have save button once I click the save button it will save the data to the server and once data is saved I load the same page again and I am displaying some information saying "Data is saved" at the bottom of the page.
嗨,我有长度的 jsp 页面,在页面底部我有保存按钮,一旦我点击保存按钮,它就会将数据保存到服务器,一旦保存数据,我会再次加载同一页面,我正在显示一些信息说“数据已保存”在页面底部。
My question is how can I load the page to show this message when page loads instead of loading page at its top.
我的问题是如何加载页面以在页面加载时显示此消息,而不是在其顶部加载页面。
<html>
<head></head>
<body>
<span> Hi </span>
.....................
.....................
.....................
.
.
.
.
.
.
//at the bottom of page
<span> Data Saved succefully</span>
</body>
</html>
So when I load the page I should see "Data Saved succefully" message.
因此,当我加载页面时,我应该看到“数据已成功保存”消息。
回答by Ashis Kumar
You can simply assign an id to the span and can redirect to the current page with #your-id
attached at the end of your url.
您可以简单地为 span 分配一个 id,并可以重定向到当前页面,并#your-id
附加在您的 url 末尾。
<a href="http://jsfiddle.net/tFcsP/show/#demo">Click to go</a>
Check this link http://jsfiddle.net/tFcsP/show/#demo
回答by SarathSprakash
回答by SarathSprakash
Using jQuery :
使用 jQuery :
$(function() {
$(window).scrollTop($('#div_name').offset().top);
});
回答by Pratim
use simple java script
使用简单的java脚本
<htm
l>
<head>
<script>
function scrollWindow()
{
window.scrollTo(100,500)
}
</script>
</head>
<body>
<input type="button" onclick="scrollWindow()" value="Scroll">
<p>SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL</p>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<p>SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL</p>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<p>SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL</p>
</body>
</html>
when you save the data and after say page load aur any response recieved then.
当您保存数据并在说页面加载之后收到任何响应时。
Heres w3 school link scroll to
继承人 w3 学校链接 滚动到