过时
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.
Indicates the amount of time, in seconds, that remain until the battery is fully charged.
Even if the time returned is precise to the second, browsers round them to a higher interval (typically to the closest 15 minutes) for privacy reasons.
var time = battery.chargingTime
On return,
time
is the remaining time in seconds until the
battery
, which is a
BatteryManager
object, is fully charged, or 0 if the battery is already fully charged. If the battery is currently discharging, this value is
Infinity
.
<div id="chargingTime">(charging time unknown)</div>
navigator.getBattery().then(function(battery) {
var time = battery.chargingTime;
document.querySelector('#chargingTime').textContent = battery.chargingTime;
});
| 规范 | 状态 | 注释 |
|---|---|---|
| Battery Status API | 候选推荐 | 初始定义 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
chargingTime
弃用
|
Chrome 38 | Edge 79 |
Firefox
16 — 52
|
IE No | Opera 25 | Safari No | WebView Android 40 |
Chrome Android
38
|
Firefox Android
10 — 16
Prefixed
|
Opera Android 25 | Safari iOS ? — ? |
Samsung Internet Android
3.0
|
完整支持
不支持
弃用。不要用于新网站。
见实现注意事项。
用户必须明确启用此特征。
要求使用供应商前缀或不同名称。
BatteryManager