--- title: GlobalEventHandlers.onplay slug: Web/API/GlobalEventHandlers/onplay translation_of: Web/API/GlobalEventHandlers/onplay ---
The onplay property of the {{domxref("GlobalEventHandlers")}} mixin is the {{event("Event_handlers", "event handler")}} for processing {{event("play")}} 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 |
|---|---|---|
| {{SpecName('HTML WHATWG','webappapis.html#handler-onplay','onplay')}} | {{Spec2('HTML WHATWG')}} |
|
{{Compat("api.GlobalEventHandlers.onplay")}}