BatteryManager:dischargingTime 属性
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
BatteryManager
接口的 dischargingTime
只读属性指示电池完全放电的剩余时间(以秒为单位),如果电池当前正在充电而不是放电或者用户代理无法报告电池状态信息则为 Infinity
。当其值发生变化时,会触发 dischargingtimechange
事件。
备注: 即使返回的时间精确到秒,出于隐私原因,浏览器会将它们舍入到更大的间隔(通常为最接近的 15 分钟的倍数)。
值
一个数字。
示例
HTML
html
<div id="dischargingTime">(电量耗尽时间未知)</div>
JavaScript
js
navigator.getBattery().then((battery) => {
const time = battery.dischargingTime;
document.querySelector("#dischargingTime").textContent =
`电池电量完全耗尽的剩余时间:${time}秒`;
});
规范
Specification |
---|
Battery Status API # dom-batterymanager-dischargingtime |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
dischargingTime |
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.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.