aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/htmlmediaelement/error_event/index.html
blob: 2fb96ad1fbe2bff8d3e0cfb4aeed834bd6003e59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
---
title: 'HTMLMediaElement: error event'
slug: Web/API/HTMLMediaElement/error_event
translation_of: Web/API/HTMLMediaElement/error_event
---
<div>{{APIRef}}</div>

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

<table class="properties">
 <tbody>
  <tr>
   <th scope="row">起泡</th>
   <td></td>
  </tr>
  <tr>
   <th scope="row">可取消</th>
   <td></td>
  </tr>
  <tr>
   <th scope="row">接口</th>
   <td>{{domxref("Event")}}</td>
  </tr>
  <tr>
   <th scope="row">事件处理器属性</th>
   <td>{{domxref("GlobalEventHandlers/onerror", "onerror")}}</td>
  </tr>
 </tbody>
</table>

<h2 id="示例">示例</h2>

<pre class="brush: js">const video = document.querySelector('video');
const videoSrc = 'https://path/to/video.webm';

video.addEventListener('error', () =&gt; {
  console.error(`Error loading: ${videoSrc}`);
});

video.setAttribute('src', videoSrc);</pre>

<h2 id="规范">规范</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">规范</th>
   <th scope="col">状态</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('HTML WHATWG', "media.html#event-media-error")}}</td>
   <td>{{Spec2('HTML WHATWG')}}</td>
  </tr>
  <tr>
   <td>{{SpecName('HTML5 W3C', "embedded-content-0.html#event-media-error")}}</td>
   <td>{{Spec2('HTML5 W3C')}}</td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器兼容性">浏览器兼容性</h2>



<p>{{Compat("api.HTMLMediaElement.error_event")}}</p>

<h2 id="更多">更多</h2>

<ul>
 <li>{{domxref("HTMLAudioElement")}}</li>
 <li>{{domxref("HTMLVideoElement")}}</li>
 <li>{{HTMLElement("audio")}}</li>
 <li>{{HTMLElement("video")}}</li>
</ul>