BatteryManager:charging 属性
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
BatteryManager
接口的 charging
只读属性是一个布尔值,指示设备的电池当前是否正在充电。当其值发生变化时,会触发 chargingchange
事件。
如果电池正在充电或者用户代理无法报告电池状态信息,则该值为 true
。否则,它是 false
。
值
一个布尔值。
示例
HTML
html
<div id="charging">(充电状态未知)</div>
JavaScript
js
navigator.getBattery().then((battery) => {
const charging = battery.charging;
document.querySelector("#charging").textContent = charging;
});
规范
Specification |
---|
Battery Status API # dom-batterymanager-charging |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
charging |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- No support
- No support
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.