HTML DOM KeyboardEvent shiftKey 属性
HTML DOM KeyboardEvent shiftKey 属性返回值(true/false)表示在事件中是否使用 Shift 键。
语法
以下是语法:
返回 **booleanValue**
event.shiftKey
示例
让我们看一个 KeyboardEvent shiftKey 属性的示例:
<!DOCTYPE html>
<html>
<head>
<title>KeyboardEvent shiftKey</title>
<style>
form {
width:70%;
margin: 0 auto;
text-align: center;
}
* {
padding: 2px;
margin:5px;
}
input[type="button"] {
border-radius: 10px;
}
</style>
</head>
<body>
<form>
<fieldset>
<legend>KeyboardEvent-shiftKey</legend>
<label>Editor:
<input type="text" id="textSelect" onkeydown="getEventData(event)" autocomplete="off">
</label>
<div id="divDisplay">I Dare you to press the shift key</div>
</fieldset>
</form>
<script>
var divDisplay = document.getElementById("divDisplay");
var textSelect = document.getElementById("textSelect");
function getEventData(InputEvent) {
if(InputEvent.shiftKey === true)
divDisplay.textContent = 'You are very brave!';
else
divDisplay.textContent = 'You scared enough?';
}
</script>
</body>
</html>输出
将产生以下输出:
在文本字段中输入任何内容之前:

在文本字段中输入错误答案后:

在文本字段中输入正确答案后:

广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP