這是我的SVG文件中的代碼「的onclick」事件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Creator: CorelDRAW X6 -->
<?xml-stylesheet href="style.css" type="text/css"?>
<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="1176px" height="617px" version="1.1" style="shape-rendering:geometricPrecision; text- rendering:geometricPrecision; image-rendering:optimizeQuality; fill-rule:evenodd; clip- rule:evenodd"
viewBox="0 0 1176 617"
xmlns:xlink="http://www.w3.org/1999/xlink">
<script xlink:href="skrypty.js" type="text/ecmascript"/>
<defs>
<clipPath id="id0">
<rect x="2" y="1" width="1176" height="617"/>
</clipPath>
</defs>
<g id="Layer_x0020_1">
<metadata id="CorelCorpID_0Corel-Layer"/>
<g style="clip-path:url(#id0)">
<image id="mainMapa.jpg" x="2" y="1" width="1176" height="617" xlink:href="mapaMain_Images\mapaMain_ImgID1.png"/>
</g>
<polygon id="fil0" class="str0" onclick="changeColor()" points="638,226 638,269 686,269 670,242 675,242 677,237 673,229 669,229 663,228 660,228 655,229 647,228 "/>
</g>
</svg>
,這裏是JavaScript代碼
var worldMap = document.getElementById("mapaSwiata").getSVGDocument();
worldMap.getElementById("fil0");
function changeColor()
{
worldMap.style.fill="brown";
}
我的目的是調用javascript函數,當有人點擊在外部SVG文件中的多邊形上。鏈接beetwen外部CSS文件和外部SVG文件完美工作,但我不知道如何連接外部JavaScript文件與SVG文件。
有什麼想法?
這不是從你的問題,你是如何包括SVG文件和腳本清晰。這對解決方案很重要。 –
我使用