aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/document/querycommandenabled
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/querycommandenabled
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/querycommandenabled')
-rw-r--r--files/zh-cn/web/api/document/querycommandenabled/index.html83
1 files changed, 83 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/document/querycommandenabled/index.html b/files/zh-cn/web/api/document/querycommandenabled/index.html
new file mode 100644
index 0000000000..e03eab3aff
--- /dev/null
+++ b/files/zh-cn/web/api/document/querycommandenabled/index.html
@@ -0,0 +1,83 @@
+---
+title: Document.queryCommandEnabled()
+slug: Web/API/Document/queryCommandEnabled
+tags:
+ - CSS
+ - CSS参考
+ - Document
+ - Method
+translation_of: Web/API/Document/queryCommandEnabled
+---
+<p>{{ApiRef("DOM")}}</p>
+
+<div class="blockIndicator note">
+<p><strong>注意</strong></p>
+该方法在部分浏览器返回的结果是不可预料的。因此,建议使用execCommand的返回值直接判断,或通过其它方式嗅探,而非使用该方法。</div>
+
+<div></div>
+
+<p><code><strong>Document.queryCommandEnabled()</strong></code> 方法可查询浏览器中指定的编辑指令是否可用。</p>
+
+<h2 id="语法">语法</h2>
+
+<pre class="syntaxbox"><var>var isEnabled</var> = document.queryCommandEnabled(<var>command</var>);
+</pre>
+
+<dl>
+ <dt>
+ <h3 id="参数">参数</h3>
+ </dt>
+ <dt><code>command</code></dt>
+ <dd>待查询的是否可用的指令.</dd>
+</dl>
+
+<h3 id="返回值">返回值</h3>
+
+<p>返回 {{jsxref("Boolean")}} 值,<code>true</code> 表示指令可用,<code>false</code>表示指令不可用<font face="consolas, Liberation Mono, courier, monospace">。</font></p>
+
+<h2 id="备注">备注</h2>
+
+<ul>
+ <li>经过测试,在部分浏览器它永远返回 <code>false</code>,而IE浏览器即使对于同样支持的属性也可能有不同返回值;有时IE还会对不支持的属性抛出异常而不是返回 <code>false</code>。</li>
+ <li>对于 <code>"cut"</code> 和 <code>"copy"</code> 指令,只有当用户启动的线程调用该方法时才返回true。</li>
+ <li><code>"paste"</code> 指令不仅当特性不可用时返回 <code>false</code> ,脚本权限不足时也一样。</li>
+</ul>
+
+<h2 id="示例">示例</h2>
+
+<pre class="brush:js">var flg = document.queryCommandEnabled("SelectAll");
+
+if(flg) {
+ document.execCommand("SelectAll", false, null); // command is enabled, run it
+}
+</pre>
+
+<h2 id="规范">规范</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">说明</th>
+ <th scope="col">状态</th>
+ <th scope="col">描述</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('HTML Editing','#querycommandenabled()','querycommandenabled')}}</td>
+ <td>{{Spec2('HTML Editing')}}</td>
+ <td>Initial definition</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+<div class="hidden">此页上的兼容性表是从结构化数据生成的。如果您想贡献数据,请访问 <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> 并向我们发送一个请求。</div>
+
+<div>{{Compat("api.Document.queryCommandEnabled")}}</div>
+
+<h2 id="参考资料">参考资料</h2>
+
+<ul>
+ <li>{{domxref("Document.execCommand()")}}</li>
+ <li>{{domxref("Document.queryCommandSupported()")}}</li>
+</ul>