在SVG中引用外部js文件,请问怎么引用
svg文件
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-flat-20030114.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100%" height="100%"> <script language="JavaScript" xlink:href="test.js"></script>
<rect id="rect1" x="40" y="35" width="50" height="20" style="fill:red" onmousemove="mouseMove(evt)" onmouseout="mouseOut(evt)"></rect>
</svg>js文件
<script language="javascript">
function mouseMove(evt){
svgtar=evt.target
svgdoc=svgtar.ownerDocument;
rect1=svgdoc.getElementById("rect1");
rect1.setAttribute("style", "fill:green");
} function mouseOut(evt){
svgtar=evt.target
svgdoc=svgtar.ownerDocument;
rect1=svgdoc.getElementById("rect1");
rect1.setAttribute("style", "fill:red");
}
</script>
为什么不能正确引用,谢谢
svg文件
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-flat-20030114.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100%" height="100%"> <script language="JavaScript" xlink:href="test.js"></script>
<rect id="rect1" x="40" y="35" width="50" height="20" style="fill:red" onmousemove="mouseMove(evt)" onmouseout="mouseOut(evt)"></rect>
</svg>js文件
<script language="javascript">
function mouseMove(evt){
svgtar=evt.target
svgdoc=svgtar.ownerDocument;
rect1=svgdoc.getElementById("rect1");
rect1.setAttribute("style", "fill:green");
} function mouseOut(evt){
svgtar=evt.target
svgdoc=svgtar.ownerDocument;
rect1=svgdoc.getElementById("rect1");
rect1.setAttribute("style", "fill:red");
}
</script>
为什么不能正确引用,谢谢
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货