onmouseover="doIn();" onmouseout="doOut();" onclick="doClick();"HTMLのタグと同様、イベント属性にJavaScriptの処理を用意しておくことで、イベント発生時の処理が行えます。通常は、あらかじめ関数として処理を定義しておき、この例のように関数の実行を値に設定しておくのがよいでしょう。
※リストが表示されない場合
AddBlockなどの広告ブロックツールがONになっているとリストなどが表示されない場合があります。これらのツールをOFFにしてみてください。
<!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" xml:lang="ja"> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <title>サンプルページ</title> <script type="text/javascript"> function doClick(){ alert("click!"); } function doIn(){ var circle1 = document.getElementById('circle1'); circle1.setAttribute('fill',"#AA3333"); } function doOut(){ var circle1 = document.getElementById('circle1'); circle1.setAttribute('fill',"#FF6666"); } </script> </head> <body> <p>SVGのサンプル</p> <svg width="200px" height="150px" xmlns="http://www.w3.org/2000/svg"> <circle id="circle1" cx="100px" cy="75px" r="50px" fill="#FF6666" stroke="#FF0000" stroke-width="5px" onmouseover="doIn();" onmouseout="doOut();" onclick="doClick();" /> </svg> </body> </html>
<< 前へ | 次へ >> |