--- title: MouseEvent.shiftKey slug: Web/API/MouseEvent/shiftKey translation_of: Web/API/MouseEvent/shiftKey ---
{{APIRef("DOM Events")}}
MouseEvent.shiftKey
是只读属性,指出触发鼠标事件时是否按住了 shift
键
var shiftKeyPressed = instanceOfMouseEvent.shiftKey
A boolean
<html> <head> <title>shiftKey example</title> <script type="text/javascript"> 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>
Specification | Status | Comment |
---|---|---|
{{SpecName('DOM3 Events','#widl-MouseEvent-shiftKey','MouseEvent.shiftKey')}} | {{Spec2('DOM3 Events')}} | No change from {{SpecName('DOM2 Events')}}. |
{{SpecName('DOM2 Events','#Events-MouseEvent','MouseEvent.shiftKey')}} | {{Spec2('DOM2 Events')}} | Initial definition. |
{{ CompatibilityTable() }}
Feature | Edge | Firefox (Gecko) | Chrome | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | {{CompatVersionUnknown}} | {{CompatVersionUnknown()}} | {{CompatVersionUnknown()}} | {{CompatVersionUnknown()}} | {{CompatVersionUnknown()}} | {{CompatVersionUnknown()}} |
Feature | Edge | Firefox Mobile (Gecko) | Android | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | {{CompatVersionUnknown}} | {{ CompatUnknown() }} | {{ CompatUnknown() }} | {{ CompatUnknown() }} | {{ CompatUnknown() }} | {{ CompatUnknown() }} |