DOMTokenList.remove()

翻译不完整。 请帮助我们翻译这篇文章!

remove() 方法从 DOMTokenList 中移除指定标记。

语法

tokenList.remove(token1[, token2[, ...]]);

参数列表

tokenN...
表示要从列表中移除的一个 DOMString。如果列表中不存在该字符串,不会出错也没有任何变化。

返回值

undefined

示例

在下面的示例中,我们使用 Element.classList 检索 <span> 元素上设置的class列表作为DOMTokenList。然后从列表中删除一个标记,并将该列表写入<span>Node.textContent 中。

HTML:

<span class="a b c"></span>

JavaScript:

var span = document.querySelector("span");
var classes = span.classList;
classes.remove("c");
span.textContent = classes;

输出如下:

要一次删除多个class,可以提供多个标记。书写顺序不必与它们在列表中出现的顺序匹配:

let span = document.getElementsByTagName("span")[0],
  classes = span.classList;

classes.remove("c", "b");
span.textContent = classes;

描述

Specification Status Comment
DOM
remove()
Living Standard Initial definition

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
removeChrome Full support 8Edge Full support 12Firefox Full support YesIE Full support 10Opera Full support YesSafari Full support 5.1WebView Android Full support 3Chrome Android Full support 18Firefox Android Full support YesOpera Android Full support YesSafari iOS Full support 5.1Samsung Internet Android Full support 1.0
Multiple arguments for remove()Chrome Full support 24Edge Full support 12Firefox Full support 26IE No support NoOpera Full support 15Safari Full support 7WebView Android Full support ≤37Chrome Android Full support 25Firefox Android Full support 26Opera Android Full support 14Safari iOS Full support 7Samsung Internet Android Full support 1.5

Legend

Full support  
Full support
No support  
No support