过时
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.

A Boolean value indicating whether or not the device's battery is currently being charged.

句法

var charging = battery.charging
					

On return, charging indicates whether or not the battery , which is a BatteryManager object, is currently being charged; if the battery is charging, this value is true . Otherwise, the value is false .

范例

HTML 内容

<div id="charging">(charging state unknown)</div>
					

JavaScript Content

navigator.getBattery().then(function(battery) {
    var charging = battery.charging;
    document.querySelector('#charging').textContent = charging ;
});
					

规范

规范 状态 注释
Battery Status API 候选推荐 初始定义

浏览器兼容性

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. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
charging 弃用 Chrome 38 Edge 79 Firefox 16 — 52
不支持 16 — 52
不支持 10 — 16 Prefixed
Prefixed Implemented with the vendor prefix: moz
52 Disabled
Disabled by default in Firefox 10, but can be enabled setting the preference dom.battery.enabled to true . Starting with Firefox 11, mozBattery is enabled by default. The Battery API is currently supported on Android, Windows, and Linux with UPower installed. Support for MacOS is available starting with Firefox 18. Firefox also provides support for the deprecated navigator.battery .
Disabled From version 52: this feature is behind the dom.battery.enabled preference. To change preferences in Firefox, visit about:config.
72
From this version onwards, BatteryManager is only available in chrome/privileged code.
IE No Opera 25 Safari No WebView Android 40 Chrome Android 38
38
Values for BatteryManager.chargingTime and BatteryManager.dischargingTime are always equal to Infinity .
Firefox Android 10 — 16 Prefixed
不支持 10 — 16 Prefixed
Prefixed Implemented with the vendor prefix: moz
不支持 16 — 52 Disabled
Disabled by default in Firefox 10.0, but can be enabled setting the preference dom.battery.enabled to true . Starting with Firefox 11.0, mozBattery is enabled by default. The Battery API is currently supported on Android, Windows, and Linux with UPower installed. Support for MacOS is available starting with Gecko 18.0 (Firefox 18.0 / Thunderbird 18.0 / SeaMonkey 2.15). Firefox also provides support for the deprecated navigator.battery .
Disabled From version 16 until version 52 (exclusive): this feature is behind the dom.battery.enabled preference. To change preferences in Firefox, visit about:config.
Opera Android 25 Safari iOS ? — ? Samsung Internet Android 3.0
3.0
Values for BatteryManager.chargingTime and BatteryManager.dischargingTime are always equal to Infinity .

图例

完整支持

完整支持

不支持

不支持

弃用。不要用于新网站。

弃用。不要用于新网站。

见实现注意事项。

用户必须明确启用此特征。

用户必须明确启用此特征。

要求使用供应商前缀或不同名称。

要求使用供应商前缀或不同名称。

另请参阅

元数据

  • 最后修改:
  1. Battery Status API
  2. BatteryManager
  3. 特性
    1. charging
    2. chargingTime
    3. dischargingTime
    4. level
    5. onchargingchange
    6. onchargingtimechange
    7. ondischargingtimechange
    8. onlevelchange
  4. 继承:
    1. EventTarget
  5. Related pages for Battery API
    1. Navigator.battery
    2. Navigator.getBattery()

版权所有  © 2014-2026 乐数软件    

工业和信息化部: 粤ICP备14079481号-1