aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/navigator/getbattery/index.html
blob: 8223faab3e5e6cced26a3a74a970b8506b1eb57b (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
---
title: Navigator.getBattery()
slug: Web/API/Navigator/getBattery
translation_of: Web/API/Navigator/getBattery
---
<p>{{ ApiRef("Battery API") }}</p>

<p><code>getBattery()方法提供了系统的电量信息,返回一个battery的promise对象,然后resolve后得到</code>{{domxref("BatteryManager")}}对象,它提供了一些新的事件,以及方法供您监控电池的状态。这个方法实现了<a href="/en-US/docs/WebAPI/Battery_Status" title="/en-US/docs/WebAPI/Battery_Status">Battery Status API</a> (查看更多细节以及使用方法和实例代码)</p>

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

<pre class="syntaxbox">navigator.getBattery().then(funcRef);</pre>

<p><code><em>funcRef</em></code> 是{{domxref("navigator.getBattery")}} 返回的battery promise对象被resolve后执行的函数,即回调函数。</p>

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

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">规范</th>
   <th scope="col">状态</th>
   <th scope="col">阶段</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName("Battery API", "#widl-Navigator-getBattery-Promise-BatteryManager", "Navigator.getBattery")}}</td>
   <td>{{Spec2('Battery API')}}</td>
   <td>初试定义</td>
  </tr>
 </tbody>
</table>

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

{{Compat("api.Navigator.getBattery")}}

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

<ul>
 <li><a href="/en-US/docs/WebAPI/Battery_Status" title="/en-US/docs/WebAPI/Battery_Status">Battery Status API</a></li>
</ul>