页面失去焦点
您好,我有一个小的 javascript 函数,在使用 ajax 更新网格后调用。我遇到了刷新网格后失去页面焦点的问题。我尝试使用以下代码来获取活动元素,刷新网格,然后将焦点重置到之前的状态。
var selectedTextArea = document.activeElement;
grid1.refresh();
document.getElementById(selectedTextArea.id).focus();
这似乎有效,只是在刷新完成执行之前设置了焦点,因此页面仍然失去焦点。关于为什么会发生这种情况以及如何解决问题有什么想法吗?
Hi I have a small javascript function I am calling after updating a grid using ajax. I ran into a problem with losing page focus after refreshing the grid. I am trying to use the following code to get the active element, refresh the grid, then reset focus to its previous state.
var selectedTextArea = document.activeElement;
grid1.refresh();
document.getElementById(selectedTextArea.id).focus();
This seems to work except that the focus is being set before the refresh has finished executing so the page still loses focus. Any ideas on why this is happeneing and how I can fix the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您的网格刷新功能正在执行异步操作。
您将需要捕获网格完成刷新,并在那里执行焦点调用。
如果不知道您使用什么框架来构建网格或刷新网格需要什么,则很难更详细地回答。更多细节可能会给出更完整的结果。
It sounds like your grid refresh function is performing an asyc operation.
You will need to capture your grid finishing its refresh, and performing your focus call there.
It is a little difficult to answer in more detail without knowing what framework you are using to build your grid or what refreshing the grid entails. More details will likely give more complete results.