使用语境
| 分类 | None |
|---|---|
| 允许内容 | 任何元素或字符数据 |
属性
crossorigin-
此属性定义了为 HTML
<script>元素定义的 CORS 设置。值类型: [ anonymous | use-credentials ]?;默认值:?;可动画:是 fetchpriority实验性 非标准-
提供在获取外部脚本时使用的相对优先级的提示。允许的值
hreftype-
此属性定义要使用的脚本语言的类型。值类型:
<media-type>;默认值:application/ecmascript;可动画:否 xlink:href已弃用
DOM 接口
此元素实现了 SVGScriptElement 接口。
示例
html
Click the circle to change colors.
<svg
viewBox="0 0 10 10"
height="120px"
width="120px"
xmlns="http://www.w3.org/2000/svg">
<circle cx="5" cy="5" r="4" />
<script>
// <![CDATA[
function getColor() {
const R = Math.round(Math.random() * 255)
.toString(16)
.padStart(2, "0");
const G = Math.round(Math.random() * 255)
.toString(16)
.padStart(2, "0");
const B = Math.round(Math.random() * 255)
.toString(16)
.padStart(2, "0");
return `#${R}${G}${B}`;
}
document.querySelector("circle").addEventListener("click", (e) => {
e.target.style.fill = getColor();
});
// ]]>
</script>
</svg>
规范
| 规范 |
|---|
| Scalable Vector Graphics (SVG) 2 # ScriptElement |
浏览器兼容性
加载中…