这是
实验性技术
检查
浏览器兼容性表格
要小心谨慎在生产中使用这之前。
onauxclick
特性为
GlobalEventHandlers
混合
EventHandler
为处理
auxclick
事件。
auxclick
event is raised when a non-primary button has been pressed on an input device (e.g., a middle mouse button). It fires after the
mousedown
and
mouseup
events, in that order.
注意:
Browser vendors are implementing this property as part of a plan to improve compatibility with regards to button behaviors. Specifically, event behavior is being updated so that
click
only fires for primary button clicks (e.g., left mouse button), while
auxclick
fires for non-primary button clicks. Historically,
click
has generally fired for the click of
any
device input button, although with browser behavior being somewhat inconsistent.
target.onauxclick = functionRef;
functionRef
is a function name or a
函数表达式
. The function receives a
MouseEvent
object as its sole argument. Within the function,
this
will be the element upon which the event was triggered.
Only one
onauxclick
handler can be assigned to an object at a time. You may prefer to use the
EventTarget.addEventListener()
method instead, since it's more flexible.
In this example we define functions for two event handlers —
onclick
and
onauxclick
. The former changes the color of the button background, while the latter changes the button foreground (text) color. You can see the two functions in action by trying the demo out with a multi-button mouse (
see it live on GitHub
; also
see the source code
).
var button = document.querySelector('button');
var html = document.querySelector('html');
function random(number) {
return Math.floor(Math.random() * number);
}
button.onclick = function() {
var rndCol = 'rgb(' + random(255) + ',' + random(255) + ',' + random(255) + ')';
button.style.backgroundColor = rndCol;
};
button.onauxclick = function() {
var rndCol = 'rgb(' + random(255) + ',' + random(255) + ',' + random(255) + ')';
button.style.color = rndCol;
}
注意
: If you are using a three-button mouse, you'll notice that the
onauxclick
handler is run when either of the non-left mouse buttons are clicked.
| 规范 | 状态 | 注释 |
|---|---|---|
|
UI Events
The definition of 'onauxclick' in that specification. |
工作草案 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
onauxclick
|
Chrome 55 | Edge 79 | Firefox 53 | IE No | Opera Yes | Safari No | WebView Android Yes | Chrome Android Yes | Firefox Android 53 | Opera Android Yes | Safari iOS No | Samsung Internet Android Yes |
完整支持
不支持
auxclick
event
GlobalEventHandlers
onabort
onanimationcancel
onanimationend
onanimationiteration
onauxclick
onblur
oncancel
oncanplay
oncanplaythrough
onchange
onclick
onclose
oncontextmenu
oncuechange
ondblclick
ondurationchange
onended
onerror
onfocus
onformdata
ongotpointercapture
oninput
oninvalid
onkeydown
onkeypress
onkeyup
onload
onloadeddata
onloadedmetadata
onloadend
onloadstart
onlostpointercapture
onmousedown
onmouseenter
onmouseleave
onmousemove
onmouseout
onmouseover
onmouseup
onpause
onplay
onplaying
onpointercancel
onpointerdown
onpointerenter
onpointerleave
onpointermove
onpointerout
onpointerover
onpointerup
onreset
onresize
onscroll
onselect
onselectionchange
onselectstart
onsubmit
ontouchcancel
ontouchstart
ontransitioncancel
ontransitionend
onwheel
BeforeUnloadEvent
DOMStringMap
ErrorEvent
HTMLAnchorElement
HTMLAreaElement
HTMLAudioElement
HTMLBRElement
HTMLBaseElement
HTMLBaseFontElement
HTMLBodyElement
HTMLButtonElement
HTMLCanvasElement
HTMLContentElement
HTMLDListElement
HTMLDataElement
HTMLDataListElement
HTMLDialogElement
HTMLDivElement
HTMLDocument
HTMLElement
HTMLEmbedElement
HTMLFieldSetElement
HTMLFormControlsCollection
HTMLFormElement
HTMLFrameSetElement
HTMLHRElement
HTMLHeadElement
HTMLHeadingElement
HTMLHtmlElement
HTMLIFrameElement
HTMLImageElement
HTMLInputElement
HTMLIsIndexElement
HTMLKeygenElement
HTMLLIElement
HTMLLabelElement
HTMLLegendElement
HTMLLinkElement
HTMLMapElement
HTMLMediaElement
HTMLMetaElement
HTMLMeterElement
HTMLModElement
HTMLOListElement
HTMLObjectElement
HTMLOptGroupElement
HTMLOptionElement
HTMLOptionsCollection
HTMLOutputElement
HTMLParagraphElement
HTMLParamElement
HTMLPictureElement
HTMLPreElement
HTMLProgressElement
HTMLQuoteElement
HTMLScriptElement
HTMLSelectElement
HTMLShadowElement
HTMLSourceElement
HTMLSpanElement
HTMLStyleElement
HTMLTableCaptionElement
HTMLTableCellElement
HTMLTableColElement
HTMLTableDataCellElement
HTMLTableElement
HTMLTableHeaderCellElement
HTMLTableRowElement
HTMLTableSectionElement
HTMLTemplateElement
HTMLTextAreaElement
HTMLTimeElement
HTMLTitleElement
HTMLTrackElement
HTMLUListElement
HTMLUnknownElement
HTMLVideoElement
HashChangeEvent
历史
ImageData
定位
MessageChannel
MessageEvent
MessagePort
Navigator
NavigatorGeolocation
NavigatorID
NavigatorLanguage
NavigatorOnLine
NavigatorPlugins
PageTransitionEvent
Plugin
PluginArray
PopStateEvent
PortCollection
PromiseRejectionEvent
RadioNodeList
Transferable
ValidityState
Window
WindowBase64
WindowEventHandlers
WindowTimers