--- title: MouseEvent.altKey slug: Web/API/MouseEvent/altKey tags: - DOM事件 - altKey - 只读属性 - 鼠标事件 translation_of: Web/API/MouseEvent/altKey ---
{{APIRef("DOM Events")}}
MouseEvent.altKey 只读属性是一个{{jsxref("Boolean")}}变量。当事件触发时,如果alt 被按下,则返回 true,否则返回false。
var altKeyPressed = instanceOfMouseEvent.altKey
<html>
<head>
<title>altKey example</title>
<script type="text/javascript">
function showChar(e){
alert(
"Key Pressed: " + String.fromCharCode(e.charCode) + "\n"
+ "charCode: " + e.charCode + "\n"
+ "ALT key pressed: " + e.altKey + "\n"
);
}
</script>
</head>
<body onkeypress="showChar(event);">
<p>
Press any character key,
with or without holding down the ALT key.<br />
You can also use the SHIFT key together with the ALT key.
</p>
</body>
</html>
| Specification | Status | Comment |
|---|---|---|
| {{SpecName('DOM3 Events','#widl-MouseEvent-altKey','MouseEvent.altkey')}} | {{Spec2('DOM3 Events')}} | No change from {{SpecName('DOM2 Events')}}. |
| {{SpecName('DOM2 Events','#Events-MouseEvent','MouseEvent.altkey')}} | {{Spec2('DOM2 Events')}} | Initial definition. |