开发者

How to scroll browser view port to top of page after an ajax submit?

开发者 https://www.devze.com 2022-12-18 13:14 出处:网络
I have an upload form -- after the user submits the form, I\'d like to scroll the window back to the top of the page (where I display some help tex开发者_JS百科t).How do I correctly scroll the window

I have an upload form -- after the user submits the form, I'd like to scroll the window back to the top of the page (where I display some help tex开发者_JS百科t). How do I correctly scroll the window back to the top of the page?


You can use the scroll method on the window object to do this:

window.scroll(0,0)

The arguments are the horizontal and vertical measure of scrolling within the window, so 0,0 brings it back to the top.


Since you're using jQuery, you could try the ScrollTo plugin, which is highly customizable.


Can you not just use the .focus() event on some tag at the top of the page?

$("input#myFirstName").focus();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号