DOMTokenList:value 属性
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
DOMTokenList
接口的 value
属性是一个字符串化器,将标记(token)列表的值序列化为字符串返回,或是清除并指定列表的值。
值
一个表示序列化后的列表内容的字符串。每一项用一个空格分隔。
示例
在以下示例中,我们将使用 Element.classList
去获取 <span>
元素的类(class)列表值(即 DOMTokenList
),然后将该值写入 <span>
的 Node.textContent
。
首先,HTML 代码如下:
html
<span class="a b c"></span>
JavaScript 代码如下:
js
const span = document.querySelector("span");
const classes = span.classList;
span.textContent = classes.value;
输出看起来像这样:
规范
Specification |
---|
DOM # ref-for-dom-domtokenlist-value② |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
value |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- See implementation notes.
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.