aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/document/hasfocus/index.html
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/document/hasfocus/index.html
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/api/document/hasfocus/index.html')
-rw-r--r--files/zh-cn/web/api/document/hasfocus/index.html122
1 files changed, 122 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/document/hasfocus/index.html b/files/zh-cn/web/api/document/hasfocus/index.html
new file mode 100644
index 0000000000..e7386bd4d1
--- /dev/null
+++ b/files/zh-cn/web/api/document/hasfocus/index.html
@@ -0,0 +1,122 @@
+---
+title: document.hasFocus
+slug: Web/API/Document/hasFocus
+tags:
+ - API
+ - DOM
+ - 参考
+ - 方法
+ - 焦点
+translation_of: Web/API/Document/hasFocus
+---
+<p>{{ ApiRef }}</p>
+
+<h3 id="Summary" name="Summary">概述</h3>
+
+<p><code><strong>Document.hasFocus()</strong></code> 方法返回一个 {{jsxref("Boolean")}},表明当前文档或者当前文档内的节点是否获得了焦点。该方法可以用来判断当前文档中的活动元素是否获得了焦点。</p>
+
+<div class="note">当查看一个文档时,当前文档中获得焦点的元素一定是当前文档的活动元素,但一个文档中的活动元素不一定获得了焦点.。例如, 一个在后台的窗口中的活动元素一定没有获得焦点。</div>
+
+<h3 id="Syntax" name="Syntax">语法</h3>
+
+<pre class="eval">focused = document.hasFocus();
+</pre>
+
+<h4 id="返回值">返回值</h4>
+
+<p>如果当前文档的活动元素获得了焦点,返回<code> true</code>,否则返回false。</p>
+
+<h3 id="Example" name="Example">例子</h3>
+
+<pre class="brush: js">&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;head&gt;
+ &lt;style type='text/css'&gt;
+ #message { font-weight: bold; }
+ &lt;/style&gt;
+
+&lt;script type='text/javascript'&gt;
+ setInterval("CheckPageFocus()", 200);
+
+ function CheckPageFocus() {
+ var info = document.getElementById("message");
+ if (document.hasFocus()) {
+ info.innerHTML = "该页面获得了焦点.";
+ }
+ else {
+ info.innerHTML = "该页面没有获得焦点.";
+ }
+ }
+
+ function OpenWindow() {
+ window.open ("<a href="http://developer.mozilla.org/">http://developer.mozilla.org/</a>", "mozdev",
+ "width=640, height=300, left=150, top=260");
+ }
+&lt;/script&gt;
+&lt;/head&gt;
+
+&lt;body&gt;
+ document.hasFocus 演示&lt;br /&gt;&lt;br /&gt;
+&lt;div id="message"&gt;等待用户操作&lt;/div&gt;&lt;br /&gt;
+&lt;button onclick="OpenWindow()"&gt;打开一个新窗口&lt;/button&gt;
+&lt;/body&gt;
+&lt;/html&gt;
+</pre>
+
+<h3 id="浏览器兼容性"><span>浏览器兼容性</span></h3>
+
+<p>{{ CompatibilityTable() }}</p>
+
+<div id="compat-desktop">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Chrome</th>
+ <th>Firefox (Gecko)</th>
+ <th>Internet Explorer</th>
+ <th>Opera</th>
+ <th>Safari</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>{{ CompatVersionUnknown() }}</td>
+ <td>{{ CompatGeckoDesktop("1.9") }}</td>
+ <td>6.0</td>
+ <td>{{ CompatNo() }}</td>
+ <td>{{ CompatVersionUnknown() }}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<div id="compat-mobile">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Android</th>
+ <th>Firefox Mobile (Gecko)</th>
+ <th>IE Mobile</th>
+ <th>Opera Mobile</th>
+ <th>Safari Mobile</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>{{ CompatUnknown() }}</td>
+ <td>{{ CompatGeckoMobile("1.9") }}</td>
+ <td>{{ CompatUnknown() }}</td>
+ <td>{{ CompatNo() }}</td>
+ <td>{{ CompatUnknown() }}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<h3 id="Specification" name="Specification">规范</h3>
+
+<ul>
+ <li><a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/#focus-management">Focus management </a></li>
+</ul>
+
+<p>{{ languages( { "en": "en/DOM/document.hasFocus","es": "es/DOM/element.hasFocus", "fr": "fr/DOM/document.hasFocus", "ja": "ja/DOM/document.hasFocus", "pl": "pl/DOM/document.hasFocus" } ) }}</p>