gpt4 book ai didi

javascript - focus() 方法仅在 Internet Explorer 中滚动到顶部

转载 作者:行者123 更新时间:2023-11-28 09:13:22 25 4
gpt4 key购买 nike

在每个浏览器中,input 上的 focus() 方法都会滚动到页面顶部。我用这样的自定义方法来破解它:

$.fn.focusNo = function () {
var x = (window.pageXOffset !== undefined) ? window.pageXOffset : (document.documentElement || document.body).scrollLeft,
y = (window.pageYOffset !== undefined) ? window.pageYOffset : (document.documentElement || document.body).scrollTop;

this.focus();
window.scrollTo(x, y);
};

但是在 Interner Explorer (9, 10) 中这个解决方案不起作用..

如何解决这个问题?

最佳答案

IE 没有 scrollTo,而是有 doScroll
此外,IE 9 及更高版本已弃用 doScroll,而是使用属性 scrollLeftscrollTop
链接至IE Scroll

关于javascript - focus() 方法仅在 Internet Explorer 中滚动到顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16013307/

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