SVG参考手册
分类 | Elements
script
script
元素相当于HTML中的script
元素,因此是写脚本的地方
任何script
元素中定义的任何函数在整个当前文档中都具有全局作用域。
用法上下文
分类 |
没有 |
---|---|
允许的内容 |
任何元素或字符数据 |
例子
以下代码片段演示了SVG script
标签的使用。在这段代码中,我们使用JavaScript来改变SVG <circle>
元素的半径。
<svg width="100%" height="100%" viewBox="0 0 100 100"
xmlns="http://www.w3.org/2000/svg">
<script type="text/javascript">
// <![CDATA[
function change(evt) {
var target = evt.target;
var radius = target.getAttribute("r");
if (radius == 15) {
radius = 45;
} else {
radius = 15;
}
target.setAttribute("r",radius);
}
// ]]>
</script>
<circle cx="50" cy="50" r="45" fill="green"
onclick="change(evt)" />
</svg>
执行结果:
属性
全局属性
- Core attributes »
- Xlink attributes »
externalResourcesRequired
具体属性
type
xlink:href
DOM界面
这个元素实现了SVGScriptElement
接口。
产品规格
Specification |
Status |
Comment |
---|---|---|
Scalable Vector Graphics (SVG) 2The definition of '<script>' in that specification. |
Candidate Recommendation |
|
Scalable Vector Graphics (SVG) 1.1 (Second Edition)The definition of '<script>' in that specification. |
Recommendation |
Initial definition |
浏览器兼容性
Feature |
Chrome |
Edge |
Firefox (Gecko) |
Internet Explorer |
Opera |
Safari |
---|---|---|---|---|---|---|
Basic support |
1.0 |
(Yes) |
1.5 (1.8) |
9.0 |
9.0 |
3.0.4 |
Feature |
Android |
Edge |
Firefox Mobile (Gecko) |
IE Phone |
Opera Mobile |
Safari Mobile |
---|---|---|---|---|---|---|
Basic support |
3.0 |
(Yes) |
1.0 (1.8) |
No support |
(Yes) |
3.0.4 |