From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/zh-cn/web/api/event.button/index.html | 81 +++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 files/zh-cn/web/api/event.button/index.html (limited to 'files/zh-cn/web/api/event.button') diff --git a/files/zh-cn/web/api/event.button/index.html b/files/zh-cn/web/api/event.button/index.html new file mode 100644 index 0000000000..1dbeb3eb35 --- /dev/null +++ b/files/zh-cn/web/api/event.button/index.html @@ -0,0 +1,81 @@ +--- +title: event.button +slug: Web/API/event.button +translation_of: Web/API/MouseEvent/button +--- +

{{ ApiRef() }}

+

概述

+

表明当前事件是由鼠标的哪个按键触发的.

+

语法

+
event.button
+
+

例子

+
var buttonCode = event.button;
+
+

该属性返回一个整数值,代表触发当前事件的鼠标按键.在通常情况下,对应关系如下:

+ +
+ 注意: IE不遵守 See QuirksMode for details.
+

The order of buttons may be different depending on how the pointing device has been configured.

+

例子

+
<script>
+var whichButton = function (e) {
+    // 处理不同的事件模型
+    var e = e || window.event;
+    var btnCode;
+
+    if ('object' === typeof e) {
+        btnCode = e.button;
+
+        switch (btnCode) {
+            case 0:
+                alert('你按了左键.');
+            break;
+            case 1:
+                alert('你按了中键.');
+            break;
+            case 2:
+                alert('你按了右键.');
+            break;
+            default:
+                alert('未知按键: ' + btnCode);
+        }
+    }
+}
+</script>
+
+<button onmouseup="whichButton(event);" oncontextmenu="event.preventDefault();">请点击鼠标...</button>
+
+

备注

+

Because mouse clicks are frequently intercepted by the user interface, it may be difficult to detect buttons other than those for a standard mouse click (usually the left button) in some circumstances.

+

Users may change the configuration of buttons on their pointing device so that if an event's button property is zero, it may not have been caused by the button that is physically left–most on the pointing device; however, it should behave as if the left button was clicked in the standard button layout.

+

规范

+

DOM 2 Events Specification: button

+

浏览器兼容性

+

Based on Jan Wolter's JavaScript Madness: Mouse Events.

+

{{ CompatibilityTable() }}

+
+ + + + + + + + + + + + + + + + + +
FeatureGeckoWebkitInternet ExplorerOpera
Basic support152398
+
+

{{ languages( { "ja": "ja/DOM/event.button", "pl": "pl/DOM/event.button" ,"en": "en/DOM/event.button" } ) }}

-- cgit v1.2.3-54-g00ecf