aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/windoweventhandlers/onlanguagechange/index.html
blob: ccabcc1c2e9458f18ae1ed1367fa97b72db1a652 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
---
title: WindowEventHandlers.onlanguagechange
slug: Web/API/WindowEventHandlers/onlanguagechange
translation_of: Web/API/WindowEventHandlers/onlanguagechange
---
<p>{{APIRef("HTML DOM")}}{{SeeCompatTable}}</p>

<p><code><strong>WindowEventHandlers.onlanguagechange</strong></code> 事件是一个属性,包含待执行的代码。当 {{domxref("Event")}} 类型的 {{event("languagechange")}} 事件被这些接口实现的对象(如 {{domxref("Window")}}{{domxref("HTMLBodyElement")}} 或者 {{domxref("HTMLIFrameElement")}} 等对象)触发时,该事件属性的代码将被运行。这样的事件在浏览器通知更佳的语言列表已被更新后被触发。关于语言列表的介绍,您可访问:{{domxref("NavigatorLanguage.languages")}}</p>

<h2 id="语法">语法</h2>

<pre class="eval"><em>object</em>.onlanguagechange = <em>function</em>;
</pre>

<h3 id="值"></h3>

<ul>
 <li><code>function</code> 是用户定义的函数的名字 ,不需要 <code>()</code> 的后缀或者任何形式参数, 或者是匿名函数,例如 <code>function(event) {...}</code>。事件处理程序总是有一个单一的形式参数,包含一个事件,这里有它的类型 {{domxref("Event")}}.</li>
</ul>

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

<pre class="brush: js">window.onlanguagechange = function(ev) { alert("languagechange event detected!"); };
</pre>

<h2 id="Specifications" name="Specifications">标准</h2>

<table class="standard-table" style="height: 49px; width: 1000px;">
 <thead>
  <tr>
   <th scope="col">标准</th>
   <th scope="col">状态</th>
   <th scope="col">备注</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{ SpecName('HTML WHATWG', '#handler-workerglobalscope-onlanguagechange', 'WindowEventHandler.onlanguagechange') }}</td>
   <td>{{ Spec2('HTML WHATWG') }}</td>
   <td>初始版本</td>
  </tr>
 </tbody>
</table>

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

<p>{{ CompatibilityTable() }}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari</th>
  </tr>
  <tr>
   <td>基础支持</td>
   <td>{{ CompatUnknown() }}</td>
   <td>{{ CompatGeckoDesktop(32.0) }}</td>
   <td>{{ CompatNo() }}</td>
   <td>{{ CompatUnknown() }}</td>
   <td>{{ CompatUnknown() }}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Chrome for Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>基础支持</td>
   <td>{{ CompatUnknown() }}</td>
   <td>{{ CompatUnknown() }}</td>
   <td>{{ CompatGeckoMobile(32.0) }}</td>
   <td>{{ CompatNo() }}</td>
   <td>{{ CompatUnknown() }}</td>
   <td>{{ CompatUnknown() }}</td>
  </tr>
 </tbody>
</table>
</div>

<h2 id="参见">参见</h2>

<ul>
 <li>{{event("languagechange")}} 事件和它的类型 {{domxref("Event")}}</li>
</ul>