From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../api/htmlmediaelement/error_event/index.html | 76 ++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 files/zh-cn/web/api/htmlmediaelement/error_event/index.html (limited to 'files/zh-cn/web/api/htmlmediaelement/error_event') diff --git a/files/zh-cn/web/api/htmlmediaelement/error_event/index.html b/files/zh-cn/web/api/htmlmediaelement/error_event/index.html new file mode 100644 index 0000000000..2fb96ad1fb --- /dev/null +++ b/files/zh-cn/web/api/htmlmediaelement/error_event/index.html @@ -0,0 +1,76 @@ +--- +title: 'HTMLMediaElement: error event' +slug: Web/API/HTMLMediaElement/error_event +translation_of: Web/API/HTMLMediaElement/error_event +--- +
{{APIRef}}
+ +

事件 error 会在因为一些错误(如网络连接错误)导致无法加载资源的时候触发。

+ + + + + + + + + + + + + + + + + + + + +
起泡
可取消
接口{{domxref("Event")}}
事件处理器属性{{domxref("GlobalEventHandlers/onerror", "onerror")}}
+ +

示例

+ +
const video = document.querySelector('video');
+const videoSrc = 'https://path/to/video.webm';
+
+video.addEventListener('error', () => {
+  console.error(`Error loading: ${videoSrc}`);
+});
+
+video.setAttribute('src', videoSrc);
+ +

规范

+ + + + + + + + + + + + + + + + + + +
规范状态
{{SpecName('HTML WHATWG', "media.html#event-media-error")}}{{Spec2('HTML WHATWG')}}
{{SpecName('HTML5 W3C', "embedded-content-0.html#event-media-error")}}{{Spec2('HTML5 W3C')}}
+ +

浏览器兼容性

+ + + +

{{Compat("api.HTMLMediaElement.error_event")}}

+ +

更多

+ + -- cgit v1.2.3-54-g00ecf