KeyboardEvent: shiftKey 属性
KeyboardEvent.shiftKey
只读属性是一个布尔值,指示事件发生时 shift 键是否被按下 (true
) 或未按下 (false
)。
按下 shift 键也可能更改事件的 key
。例如,按下 B 会生成 key: "b"
,而同时按下 Shift 会生成 key: "B"
。
值
布尔值。
示例
html
<html lang="en-US">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>shiftKey example</title>
<script>
function showChar(e) {
alert(
"Key Pressed: " +
String.fromCharCode(e.charCode) +
"\n" +
"charCode: " +
e.charCode +
"\n" +
"SHIFT key pressed: " +
e.shiftKey +
"\n" +
"ALT key pressed: " +
e.altKey +
"\n",
);
}
</script>
</head>
<body onkeypress="showChar(event);">
<p>
Press any character key, with or without holding down the SHIFT key.<br />
You can also use the SHIFT key together with the ALT key.
</p>
</body>
</html>
规范
规范 |
---|
UI 事件 # dom-keyboardevent-shiftkey |
浏览器兼容性
BCD 表格仅在浏览器中加载