GlobalEventHandlers.onplay

The onplay property of the GlobalEventHandlers mixin is the EventHandler for processing 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
HTML Living Standard
onplay
Living Standard

 

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
onplayChrome Full support YesEdge ? Firefox Full support 3.5IE ? Opera ? Safari ? WebView Android Full support YesChrome Android Full support YesFirefox Android Full support 4Opera Android ? Safari iOS ? Samsung Internet Android ?

Legend

Full support  
Full support
Compatibility unknown  
Compatibility unknown

相关知识