BatteryManager:chargingTime 属性

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

安全上下文: 此项功能仅在一些支持的浏览器安全上下文(HTTPS)中可用。

BatteryManager 接口的 chargingTime 只读属性指示电池充满电所需要的时间(以秒为单位),如果电池充满电或用户代理无法报告电池状态信息则为 0。如果电池当前正在耗电,则其值为 Infinity。当其值更改时,会触发 chargingtimechange 事件。

备注: 即使返回的时间精确到秒,出于隐私原因,浏览器会将它们舍入到更大的间隔(通常为最接近的 15 分钟的倍数)。

一个数字。

示例

HTML

html
<div id="chargingTime">(充电时间未知)</div>

JavaScript

js
navigator.getBattery().then((battery) => {
  const time = battery.chargingTime;

  document.querySelector("#chargingTime").textContent =
    `电池完全充满电所需的时间:${time}`;
});

规范

Specification
Battery Status API
# dom-batterymanager-chargingtime

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
chargingTime

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
No support
No support
Has more compatibility info.

参见