svg和js交互
2014-03-08 10:12
411 查看
//1
使用xlink在svg文档中引入javascript:
//<?xml version="1.0" encoding="UTF-8"
standalone="yes"?>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="3.5in" height="1in">
<title>Listing 24-1 from the XML
Bible</title>
<circle id="x" r="30" cx="34" cy="34"
style="fill: red; stroke: blue; stroke-width: 2"
/>
<script type="text/javascript"
xlink:href="a.js">
</script>
</svg>
2 在svg文档中内嵌入javascript代码:
<?xml version="1.0" encoding="UTF-8"
standalone="yes"?>
<svg xmlns="http://www.w3.org/2000/svg"
width="3.5in" height="1in">
<title>Listing 24-1 from the XML
Bible</title>
<script type="text/javascript">
<![CDATA[
alert(123);
]]>
</script>
<circle r="30" cx="34" cy="34"
style="fill: red; stroke: blue; stroke-width: 2"
/>
</svg>
<script type="text/javascript">
<![CDATA[
具体的js代码
]]>
3通过HTML 改变SVG中的属性
//<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document
</title>
<meta name="generator" content="editplus"
/>
<meta name="author" content=""
/>
<meta name="keywords" content=""
/>
<meta name="description" content=""
/>
<script type="text/javascript">
<!--
var changeR = function (opration){
var svgDoc =
document.getElementByIdx_x("svgmapctrl").getSVGDocument();
var circle =
svgDoc.getElementById("circle1");
var r =
parseInt(circle.getAttribute("r"));
if(opration
== '+' && r<150)
circle.setAttribute("r",r+10);
if(opration
== '-' && r>10)
circle.setAttribute("r",r-10);
}
//-->
</script>
</head>
<body>
<embed width="300" height="300"
type="image/svg-xml" id="svgmapctrl"
pluginspage="http://www.adobe.com/svg/viewer/install/"
src="svg2js.svg"
></embed><br
/>
<input type="button" value="变大"
onclick="changeR('+')"
/> <input
type="button" value="缩小" onclick="changeR('-')"
/>
</body>
</html>
使用xlink在svg文档中引入javascript:
//<?xml version="1.0" encoding="UTF-8"
standalone="yes"?>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="3.5in" height="1in">
<title>Listing 24-1 from the XML
Bible</title>
<circle id="x" r="30" cx="34" cy="34"
style="fill: red; stroke: blue; stroke-width: 2"
/>
<script type="text/javascript"
xlink:href="a.js">
</script>
</svg>
2 在svg文档中内嵌入javascript代码:
<?xml version="1.0" encoding="UTF-8"
standalone="yes"?>
<svg xmlns="http://www.w3.org/2000/svg"
width="3.5in" height="1in">
<title>Listing 24-1 from the XML
Bible</title>
<script type="text/javascript">
<![CDATA[
alert(123);
]]>
</script>
<circle r="30" cx="34" cy="34"
style="fill: red; stroke: blue; stroke-width: 2"
/>
</svg>
<script type="text/javascript">
<![CDATA[
具体的js代码
]]>
3通过HTML 改变SVG中的属性
//<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document
</title>
<meta name="generator" content="editplus"
/>
<meta name="author" content=""
/>
<meta name="keywords" content=""
/>
<meta name="description" content=""
/>
<script type="text/javascript">
<!--
var changeR = function (opration){
var svgDoc =
document.getElementByIdx_x("svgmapctrl").getSVGDocument();
var circle =
svgDoc.getElementById("circle1");
var r =
parseInt(circle.getAttribute("r"));
if(opration
== '+' && r<150)
circle.setAttribute("r",r+10);
if(opration
== '-' && r>10)
circle.setAttribute("r",r-10);
}
//-->
</script>
</head>
<body>
<embed width="300" height="300"
type="image/svg-xml" id="svgmapctrl"
pluginspage="http://www.adobe.com/svg/viewer/install/"
src="svg2js.svg"
></embed><br
/>
<input type="button" value="变大"
onclick="changeR('+')"
/> <input
type="button" value="缩小" onclick="changeR('-')"
/>
</body>
</html>
相关文章推荐
- SVG与html的交互(svg的js与html的js互调用)
- SVG与html的交互(svg的js与html的js互调用)
- 转载: SVG与JS的交互
- SVG与JS的交互
- SVG与JS的交互
- SVG与html的交互(svg的js与html的js互调用)
- Android Studio第三十七期 - webview与js交互
- duilib + cef简单浏览器的demo2--c++和js交互
- Android JS 与本地代码交互---JSBridge使用注意事项
- 这下好了,可以做混合模式app了,js和java交互
- 基于V8引擎的C++和JS的相互交互
- 省市区三级联动效果--城市数据来源百度js文件,无需后台交互
- WebView基础一:Android WebView与JS的交互
- (转)Silverlight 与 JS交互
- 工作中遇到的问题之WebView与JS交互问题
- WebView加载html后的JS交互
- Java与js的交互
- node.js 命令行框架 yargs 和你的程序实现交互
- Android中webview与native之间的交互方式(jsbridge)
- 安卓混合开发实例——JS与Java的交互