--- 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. |
{{ CompatibilityTable() }}
Feature | Firefox (Gecko) | Chrome | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | {{CompatVersionUnknown()}} | {{CompatVersionUnknown()}} | {{CompatVersionUnknown()}} | {{CompatVersionUnknown()}} | {{CompatVersionUnknown()}} |
Feature | Firefox Mobile (Gecko) | Android | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | {{ CompatUnknown() }} | {{ CompatUnknown() }} | {{ CompatUnknown() }} | {{ CompatUnknown() }} | {{ CompatUnknown() }} |