blob: c45248af1c04649d1af0eafe77ea936218f51319 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
---
title: script
slug: Web/SVG/Element/script
tags:
- SVG
- 元素
- 参考
- 脚本
translation_of: Web/SVG/Element/script
---
<p>一个SVG脚本元素等同于HTML中的<code><a href="/en-US/HTML/Element/Script">script</a>元素,因此这个位置是面向脚本的(例如,ECMAScript)。</code></p>
<p>任何定义在<code>script</code>元素中的函数拥有一个跨当前文档的全局范围。</p>
<h2 id="用法">用法</h2>
<p>{{svginfo}}</p>
<h2 id="示例">示例</h2>
<p>下面的代码片段演示了SVG <code>script</code>标签的作用。在代码中,我们使用JavaScript改变SVG {{SVGElement("circle")}} 元素的半径。</p>
<pre class="brush: html"><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>
</pre>
<p>示例输出:</p>
<p>{{EmbedLiveSample("Example",150,165)}}</p>
<h2 id="属性">属性</h2>
<h3 id="全局属性">全局属性</h3>
<ul>
<li><a href="/en-US/SVG/Attribute#Core">核心属性</a> »</li>
<li><a href="/en-US/SVG/Attribute#XLink">Xlink属性</a> »</li>
<li>{{SVGAttr("externalResourcesRequired")}}</li>
</ul>
<h3 id="专有属性">专有属性</h3>
<ul>
<li>{{SVGAttr("type")}}</li>
<li>{{SVGAttr("xlink:href")}}</li>
</ul>
<h2 id="DOM接口">DOM接口</h2>
<p>该元素实现了<code><a href="/en-US/DOM/SVGScriptElement">SVGScriptElement</a></code>接口。</p>
<h2 id="浏览器兼容性">浏览器兼容性</h2>
<p>{{CompatibilityTable}}</p>
<div id="compat-desktop">
<table class="compat-table">
<tbody>
<tr>
<th>Feature</th>
<th>Chrome</th>
<th>Firefox (Gecko)</th>
<th>Internet Explorer</th>
<th>Opera</th>
<th>Safari</th>
</tr>
<tr>
<td>Basic support</td>
<td>1.0</td>
<td>{{CompatGeckoDesktop('1.8')}}</td>
<td>{{CompatIE('9.0')}}</td>
<td>{{CompatOpera('9.0')}}</td>
<td>{{CompatSafari('3.0.4')}}</td>
</tr>
</tbody>
</table>
</div>
<div id="compat-mobile">
<table class="compat-table">
<tbody>
<tr>
<th>Feature</th>
<th>Android</th>
<th>Firefox Mobile (Gecko)</th>
<th>IE Phone</th>
<th>Opera Mobile</th>
<th>Safari Mobile</th>
</tr>
<tr>
<td>Basic support</td>
<td>{{CompatAndroid('3.0')}}</td>
<td>{{CompatGeckoMobile('1.8')}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatSafari('3.0.4')}}</td>
</tr>
</tbody>
</table>
</div>
<p>该表格基于<a href="/en-US/SVG/Compatibility_sources">这些资源</a>。</p>
<h2 id="参见">参见</h2>
<ul>
<li><a href="/en-US/HTML/Element/Script">HTML中的<code>script</code>元素</a></li>
</ul>
<p>{{SVGRef}}</p>
|