GlobalEventHandlers.onplay

The onplay property of the GlobalEventHandlers mixin is the event handler for processing play (en-US) events.

语法

element.onplay = handlerFunction;
var handlerFunction = element.onplay;

handlerFunction 应该是 null 或者 JavaScript function 指定事件的处理程序。

示例

<p>此示例演示如何将“onplay”事件分配给视频元素</p>

<video controls onplay="alertPlay()">
  <source src="mov_bbb.mp4" type="video/mp4">
  <source src="mov_bbb.ogg" type="video/ogg">
  Your browser does not support HTML5 video.
</video>

<p>Video courtesy of <a href="http://www.bigbuckbunny.org/" target="_blank">Big Buck Bunny</a>.</p>

<script>
function alertPlay() {
  alert("视频开始播放啦。");
}
</script>

规范

Specification Status Comment
HTML Living Standard
onplay
Living Standard

 

浏览器兼容性

BCD tables only load in the browser

相关知识