MDN wants to learn about developers like you: https://qsurvey.mozilla.com/s3/MDN-dev-survey

Document.queryCommandEnabled()

这篇翻译不完整。请帮忙从英语翻译这篇文章

 Document.queryCommandEnabled() 方法用来查询浏览器是否支持指定的富文本编辑指令。

语法

isEnabled = document.queryCommandEnabled(command);

参数

command
要查询的是否支持的指令.

返回值

返回一个 Boolean 值,返回true 代表指令启用,返回false则代表指未启用

  • For 'cut' and 'copy' commands the method only returns true when called from a user-initiated thread.
  • The 'paste' command return false not only if the feature is unavailable, but also if the script calling it has insufficient privileges to perform the action.

示例

var flg = document.queryCommandEnabled("SelectAll");

if(flg) {
  document.execCommand("SelectAll", false, null); // command is enabled, run it
}

说明

说明 状态 描述
HTML Editing APIs
querycommandenabled
Editor's Draft Initial definition

浏览器兼容性

  
Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari
Basic support 17 (Yes) 9.0 (9.0)[1] 4.0 ? ?
  
Feature Android Edge Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support ? (Yes) 9.0 (9.0)[1] ? ? ?

[1] Before Firefox 41, queryCommandEnabled() with arguments cut, copy or paste would throw errors unless the script had special privileges.

See also

 

 

文档标签和贡献者

 此页面的贡献者: trto1987, ucev
 最后编辑者: trto1987,