Document: phương thức queryCommandEnabled()
Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.
Non-standard: This feature is not standardized. We do not recommend using non-standard features in production, as they have limited browser support, and may change or be removed. However, they can be a suitable alternative in specific cases where no standard option exists.
Note:
Mặc dù phương thức execCommand() đã lỗi thời, nếu bạn quyết định sử dụng nó vì những lý do được nêu trên trang đó, bạn nên cân nhắc kiểm tra khả năng sẵn có của lệnh bằng cách sử dụng queryCommandEnabled() để đảm bảo tương thích.
Phương thức Document.queryCommandEnabled() báo cáo liệu lệnh trình soạn thảo đã chỉ định có được trình duyệt bật hay không.
Cú pháp
queryCommandEnabled(command)
Tham số
command-
Lệnh cần xác định hỗ trợ.
Giá trị trả về
Trả về một giá trị boolean là true nếu lệnh được bật và false nếu lệnh không được bật.
Ghi chú
- Đối với các lệnh
"cut"và"copy", phương thức chỉ trả về true khi được gọi từ một luồng do người dùng khởi tạo. - Lệnh
"paste"trả vềfalsekhông chỉ khi tính năng không khả dụng, mà còn nếu tập lệnh gọi nó không có đủ quyền để thực hiện hành động.
Ví dụ
const flg = document.queryCommandEnabled("SelectAll");
if (flg) {
document.execCommand("SelectAll", false, null); // lệnh được bật, chạy nó
}
Đặc tả kỹ thuật
Tính năng này không thuộc bất kỳ đặc tả kỹ thuật hiện tại nào. Nó không còn nằm trong lộ trình trở thành tiêu chuẩn. Có một bản nháp đặc tả W3C execCommand không chính thức.