gpt4 book ai didi

c# - 将焦点设置在屏幕顶部 jquery

转载 作者:行者123 更新时间:2023-11-30 15:02:57 27 4
gpt4 key购买 nike

我有一个包含多个选项卡的页面,我使用 jquery 根据 href 单击显示和隐藏它们。每当我点击“a href”时,页面就会向下滚动。我试图将焦点设置在页面顶部。这是我在 Jquery 中的第一个项目。我尝试了以下但仍然不起作用。

  1. 滚动(0, 0);
  2. window.scrollTo(0,0);
  3. window.scrollTo(0, document.body.scrollHeight);
  4. var ctrl = document.getElementById('lnkCreateJob'); ctrl.focus();

请就此事分享一些信息。

最佳答案

像这样尝试:

$(".gototop").click(function(){
var focusElement = $("#contents");
$(focusElement).focus();
ScrollToTop(focusElement);
});

function ScrollToTop(el) {
$('html, body').animate({ scrollTop: $(el).offset().top - 50 }, 'slow');
}

SEE DEMO

关于c# - 将焦点设置在屏幕顶部 jquery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12190132/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com