From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/zh-cn/web/svg/element/script/index.html | 130 ++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 files/zh-cn/web/svg/element/script/index.html (limited to 'files/zh-cn/web/svg/element/script/index.html') diff --git a/files/zh-cn/web/svg/element/script/index.html b/files/zh-cn/web/svg/element/script/index.html new file mode 100644 index 0000000000..c45248af1c --- /dev/null +++ b/files/zh-cn/web/svg/element/script/index.html @@ -0,0 +1,130 @@ +--- +title: script +slug: Web/SVG/Element/script +tags: + - SVG + - 元素 + - 参考 + - 脚本 +translation_of: Web/SVG/Element/script +--- +

一个SVG脚本元素等同于HTML中的script元素,因此这个位置是面向脚本的(例如,ECMAScript)。

+ +

任何定义在script元素中的函数拥有一个跨当前文档的全局范围。

+ +

用法

+ +

{{svginfo}}

+ +

示例

+ +

下面的代码片段演示了SVG script标签的作用。在代码中,我们使用JavaScript改变SVG {{SVGElement("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>
+
+ +

示例输出:

+ +

{{EmbedLiveSample("Example",150,165)}}

+ +

属性

+ +

全局属性

+ + + +

专有属性

+ + + +

DOM接口

+ +

该元素实现了SVGScriptElement接口。

+ +

浏览器兼容性

+ +

{{CompatibilityTable}}

+ +
+ + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support1.0{{CompatGeckoDesktop('1.8')}}{{CompatIE('9.0')}}{{CompatOpera('9.0')}}{{CompatSafari('3.0.4')}}
+
+ +
+ + + + + + + + + + + + + + + + + + + +
FeatureAndroidFirefox Mobile (Gecko)IE PhoneOpera MobileSafari Mobile
Basic support{{CompatAndroid('3.0')}}{{CompatGeckoMobile('1.8')}}{{CompatNo}}{{CompatVersionUnknown}}{{CompatSafari('3.0.4')}}
+
+ +

该表格基于这些资源

+ +

参见

+ + + +

{{SVGRef}}

-- cgit v1.2.3-54-g00ecf