有没有什么方法在JavaScript中来关注文档(内容区域)? [英] Is there any way in JavaScript to focus the document (content area)?

查看:106
本文介绍了有没有什么方法在JavaScript中来关注文档(内容区域)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么办法可以将焦点设置到JavaScript中的文档,即内容区域? document.focus()似乎没有做任何事情。

Is there any way to set focus to the document, i.e. the content area, in JavaScript? document.focus() doesn’t seem to do anything.

推荐答案

HTML 4.01 焦点只是在表单控制和链接等元素的背景下进行讨论。在 HTML 5 中,讨论得更为广泛。但是,文档的焦点如何工作主要是依赖于浏览器。

In HTML 4.01, focus is only discussed in the context of elements such as form controls and links. In HTML 5, it is discussed much more widely. However, how focus works for documents is mostly browser dependent.

您可以尝试:

You might try:

// Give the document focus
window.focus();

// Remove focus from any focused element
if (document.activeElement) {
    document.activeElement.blur();
}

非常好支持

这篇关于有没有什么方法在JavaScript中来关注文档(内容区域)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆