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

HTMLMediaElement: play event

· 52CE 我爱测

当 `paused` 属性由 `true` 转换为 `false` 时触发 `play` 事件,事件触发原因一般为 `play()` 方法调用,或者 `autoplay` 标签设置。

HTMLMediaElement

当 paused 属性由 true 转换为 false 时触发 play 事件,事件触发原因一般为 play() 方法调用,或者 autoplay 标签设置。

<table class="properties"> <tbody> <tr> <th scope="row">Bubbles</th> <td>No</td> </tr> <tr> <th scope="row">Cancelable</th> <td>No</td> </tr> <tr> <th scope="row">Interface</th> <td>Event</td> </tr> <tr> <th scope="row">Target</th> <td>Element</td> </tr> <tr> <th scope="row">Default Action</th> <td>None</td> </tr> <tr> <th scope="row">Event handler property</th> <td>GlobalEventHandlers.onplay</td> </tr> <tr> <th scope="row">Specification</th> <td> <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-element.html#event-media-playing" >HTML5 media</a > </td> </tr> </tbody> </table>

Examples

下方的例子监听了 HTMLMediaElement 标签的 play 事件,并且在事件触发后在控制台打印相应的信息。

Using addEventListener():

const video = document.querySelector("video");

video.addEventListener("play", (event) => {
  console.log(
    "The Boolean paused property is now false. Either the " +
      "play() method was called or the autoplay attribute was toggled.",
  );
});

Using the onplay event handler property:

const video = document.querySelector("video");

video.onplay = (event) => {
  console.log(
    "The Boolean paused property is now false. Either the " +
      "play() method was called or the autoplay attribute was toggled.",
  );
};

Specifications

Browser compatibility

Related Events

  • HTMLMediaElement.playing_event
  • HTMLMediaElement.waiting_event
  • HTMLMediaElement.seeking_event
  • HTMLMediaElement.seeked_event
  • HTMLMediaElement.ended_event
  • HTMLMediaElement.loadedmetadata_event
  • HTMLMediaElement.loadeddata_event
  • HTMLMediaElement.canplay_event
  • HTMLMediaElement.canplaythrough_event
  • HTMLMediaElement.durationchange_event
  • HTMLMediaElement.timeupdate_event
  • HTMLMediaElement.play_event
  • HTMLMediaElement.pause_event
  • HTMLMediaElement.ratechange_event
  • HTMLMediaElement.volumechange_event
  • HTMLMediaElement.suspend_event
  • HTMLMediaElement.emptied_event
  • HTMLMediaElement.stalled_event

See Also

  • HTMLAudioElement
  • HTMLVideoElement
  • audio
  • video

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

资料来源与适用范围

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

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

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