KeyboardLayoutMap:has() 方法
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
KeyboardLayoutMap
接口的 has()
方法返回一个布尔值,指示该对象是否具有指定键的元素。
在 UI 事件 KeyboardEvent 代码值规范中可以找到有效键的列表。
该方法与 Map.prototype.has()
相似。
语法
js
has(key)
参数
key
-
要在映射中搜索的元素的键。
返回值
Boolean
值,表示是否找到了指定的键。
示例
以下示例检查与英语 QWERTY 键盘上“W”键对应的键盘代码关联的位置或布局特定的字符串是否存在。
js
navigator.keyboard.getLayoutMap().then((keyboardLayoutMap) => {
console.log(keyboardLayoutMap.has("KeyW"));
});
规范
Specification |
---|
ECMAScript® 2025 Language Specification # sec-map.prototype.has |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
has |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- No support
- No support
- Experimental. Expect behavior to change in the future.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.