--- title: Window.ongamepadconnected slug: Web/API/Window/ongamepadconnected tags: - API - Event Handler - Experimental - Gamepad API - Property - Reference - Window - gamepadconnected - ongamepadconnected - 手柄 - 游戏 translation_of: Web/API/Window/ongamepadconnected ---
{{domxref("Window")}} 接口的 ongamepadconnected
属性是一个事件处理程序,它将在游戏手柄连接时运行 (即当 {{event('gamepadconnected')}} 事件触发时)。
此方法响应的对象类型是 {{domxref("GamepadEvent")}}.
window.ongamepadconnected = function() { ... };
window.ongamepadconnected = function(event) {
// 手柄上所有的可用按键和手柄控制元件上各轴向数值都能在此获取
event.gamepad;
};
Specification | Status | Comment |
---|---|---|
{{SpecName('Gamepad ', '#event-gamepadconnected', 'gamepadconnected event')}} | {{Spec2('Gamepad')}} | Initial definition |
{{Compat("api.Window.ongamepadconnected")}}