switch

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.

switch元素对它的直接子元素上的属性requiredFeatures、属性requiredExtensions 和 属性systemLanguage按照顺序进行评估,然后处理和呈现第一个评估为true的子元素。其他子元素会被绕过不会被呈现。如果某个子元素是容器元素比如说是一个<g>元素,那么整个子树会被处理呈现或者全部绕过不呈现。

注意:属性display和属性visibility的值对switch 元素处理是不起作用的。特别是,在switch 元素的子元素上设置display为 none,对switch 元素的 true/false 测试处理不起作用。

使用上下文

类别容器元素
允许的内容任意数量、任意顺序的下列元素:
动画元素
描述性元素
形状元素
<a><foreignObject><g><image><svg><switch><text><use>

示例

属性

全局属性

专有属性

DOM 接口

该元素实现了 SVGSwitchElement 接口。

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
switch
systemLanguage

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support