SVG – Learning by Coding

[ get_setId.svg --> Grafik anzeigen ]

 1: <?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
 2: <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
 3:   "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd" [
 4:   <!ATTLIST svg xmlns:xlink CDATA #FIXED "http://www.w3.org/1999/xlink">
 5: ]>
 6: 
 7: <!-- SVG Learning by Coding http://www.datenverdrahten.de/svglbc/ -->
 8: <!--    AuthorDrThomas Meinike 06/03 thomas@handmadecode.de     -->
 9: 
10: <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
11: 
12:   <title>SVG Learning by Coding</title>
13:   <desc>SVG-Spezifikation in Beispielen</desc>
14: 
15:   <defs>
16: 
17:     <script type="text/javascript">
18:       <![CDATA[
19: 
20:       function get_setId(click_evt)
21:       {
22:         var obj,id,r,g,b,rgb;
23: 
24:         // aktuelles Objekt finden
25:         obj=click_evt.target;
26: 
27:         // aktuelle ID auslesen
28:         id=obj.getId();
29:         alert("Aktuelle ID: "+id);
30: 
31:         // neue ID setzen und ueber diese ID die Fuellfarbe aendern
32:         obj.setId("test"+Math.round(Math.random()*100));
33:         id=obj.getId();
34:         alert("Neue ID: "+id);
35: 
36:         r=Math.floor(Math.random()*256);
37:         g=Math.floor(Math.random()*256);
38:         b=Math.floor(Math.random()*256);
39:         rgb="rgb("+r+","+g+","+b+")";
40:         obj.ownerDocument.getElementById(id).style.setProperty("fill",rgb,"");
41:       }
42: 
43:       ]]>
44:     </script>
45: 
46:   </defs>
47: 
48:   <text x="20" y="30" style="fill: #000; font-size: 24px">
49:     Die Methoden getId() bzwsetId()</text>
50: 
51:   <circle id="kreis" cx="200" cy="100" r="30"
52:     style="fill: #090" onclick="get_setId(evt)"/>
53:   
54:   <text x="160" y="150">Kreis anklicken!</text>
55: 
56: </svg>

[zum Anfang]