且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在提交按钮单击后在jquery中将焦点设置在页面顶部。

更新时间:2022-10-19 13:43:22

像Aravindba所说,你不能专注于页面上的非输入项目。



但是,当用户点击提交按钮时,您可以通过滚动到页面顶部来设置设置视图。



 


' form')。on(' submit' function (){

' html,body')。animate({scrollTop: 0 },' slow');
});





通过这种方式,您的页面轻轻地放到顶部o提交表单时的页面。



您可以通过将表单更改为更具体的代码特定表单的ID或名称,如


Hi,


How can iset the focus of the current page to the top of page so when click submit button using jquery??

Like Aravindba said, you can't focus on non input items on your page.

However, you make "set view" by scrolling to the top of your page when the user clicks the submit button.



('form').on('submit', function() {


('html, body').animate({scrollTop:0}, 'slow'); });



This way, your page gently eases to the top of your page when the form is submitted.

You can make the code more specific by changing form to the id or name of a particular form like