[問題] 請問在HTML檔裡嵌入SVG檔?
在一個SVG檔裡面寫了一些javascript程式,
直接開檔案起來很正常
可是我用做好的HTML網頁去讀這個SVG檔,
SVG裡面的程式都沒有動作
請問我該如何去讓觸發裡面的event
下面是一個正常的test.SVG檔
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"" rel="nofollow">http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" xmlns="" rel="nofollow">http://www.w3.org/2000/svg">
<rect id="bkrect" width="600" height="300" fill="white" stroke="gray"
onmouseover="run(evt)"/>
<script type="text/javascript">
<![CDATA[
function run(evt)
{
var eventType=evt.type;
alert("this is SVG!,eventType = "+eventType)
}
]]>
</script>
</svg>
下面是HTML檔
<html><head>
<title>SVG in HTML</title>
</head>
<body>
<object id="svg1" data="test.svg" width="700" height="500"
type="image/svg+xml"></object>
</body>
</html>
我mouse移入這個<object>完全沒有反應耶~~
我知道可以在HTML寫一些
xx = document.getElementById("svg1");
yy = xx.contentDocument;
再加上getAttribute,setAttribute來讓svg檔做出一些動畫
但是寫在svg裡面的程式為什麼不會動?
另外請問為什麼要加<![CDATA[ 跟 ]]>
不寫好像也沒關係呀~~
--
麻將 手順也~
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 122.146.196.216
※ 編輯: toshii 來自: 122.146.196.216 (03/25 11:08)
推
03/26 00:39, , 1F
03/26 00:39, 1F
→
03/26 00:39, , 2F
03/26 00:39, 2F
→
03/26 00:39, , 3F
03/26 00:39, 3F
Ajax 近期熱門文章
PTT數位生活區 即時熱門文章