大网数据广告活动
Web 标准与前端开发

PointerEvent: pointerType property

· 52CE 我爱测

The **`pointerType`** read-only property of the PointerEvent interface indicates the device type (mouse, pen, or touch) that caused a given pointer event.

Pointer Events

The pointerType read-only property of the PointerEvent interface indicates the device type (mouse, pen, or touch) that caused a given pointer event.

Value

The event's pointer type. The supported values are the following strings:

  • "mouse"
    • : The event was generated by a mouse device.
  • "pen"
    • : The event was generated by a pen or stylus device.
  • "touch"
    • : The event was generated by a touch, such as a finger.

If the device type cannot be detected by the browser, the value can be an empty string (""). If the browser supports pointer device types other than those listed above, the value should be vendor-prefixed to avoid conflicting names for different types of devices.

Examples

This example illustrates using the value of the pointerType property to call the appropriate pointer type processing function.

targetElement.addEventListener("pointerdown", (event) => {
  // Call the appropriate pointer type handler
  switch (event.pointerType) {
    case "mouse":
      process_pointer_mouse(event);
      break;
    case "pen":
      process_pointer_pen(event);
      break;
    case "touch":
      process_pointer_touch(event);
      break;
    default:
      console.log(`pointerType ${event.pointerType} is not supported`);
  }
});

Specifications

Browser compatibility

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。