jQuery focus without scroll

前端 未结 7 2202
时光取名叫无心
时光取名叫无心 2020-12-08 13:48

How can I focus to a HTML element (ex. \"a\") and do not change the current scroll settings.

For ex. if I use:

$(\'#link\').focus();
<
相关标签:
7条回答
  • 2020-12-08 14:22

    The reason why this is so hard for you is because you aren't supposed to do it. The browsers are designed to help the user avoid websites that do stuff like this, because a link the has focus will activate by hitting return or space on the keyboard, and users rarely wish to follow a link they are not aware is there.

    Try to work with the browser instead of against it, and you will usually end up with happier users.

    0 讨论(0)
提交回复
热议问题