【发布时间】:2017-02-01 06:11:30
【问题描述】:
此问题参考了此处发布的解决方案。 https://stackoverflow.com/a/2600261/5086633
我在 IE 中遇到了类似的问题,但即使添加了很多延迟200,这在我的应用程序中也没有按预期工作。输入框只是间歇性地获得焦点,即使页面在 IE 中呈现,它也会跳过关注输入字段。我还尝试从$(document).ready(function(){ 和$(window).load(function() { 调用setTimeout 函数,如下所示,但没有成功。
当我在本地测试它并作为纯 html 文件但不在我的应用程序中时,此代码可以正常工作。
谁能帮我修复/或提供调试/在 IE 中调试此问题的线索,以便每次在 IE 中呈现页面时输入字段都会获得焦点?
脚注:- 它在 Firefox 中运行良好(没有延迟),而在 Chrome 中,focus 工作需要小延迟。
$(document).ready(function(){
setTimeout(function() { document.getElementById('testfocus').focus(); }, 200);
});
$(window).load(function() {
// executes when complete page is fully loaded, including all frames, objects and images
setTimeout(function() { document.getElementById('testfocus').focus(); }, 200);
});
setTimeout(function() { document.getElementById('testfocus').focus(); }, 200);
<html>
<head>
</head>
<body>
<input id="testfocus"/>
</body>
</html>
【问题讨论】:
标签: javascript html internet-explorer dom