JavaScript 中的 altKey 鼠标事件的作用是什么?
htmljavascriptprogramming scripts更新于 2026/1/14 7:08:17
altkey 鼠标事件属性用于显示单击鼠标按钮时是否按下了 SHIFT 键。
示例
您可以尝试运行以下代码来了解如何在 JavaScript 中实现 altKey 鼠标事件。
<!DOCTYPE html>
<html>
<body onmousedown="funcAltKey(event)">
<div>Press and hold ALT key and then click here.</div>
<script>
function funcAltKey(event) {
if (event.altKey) {
alert("ALT key: Pressed");
} else {
alert("ALT key: NOT Pressed");
}
}
</script>
</body>
</html>
相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

