[問題] 請問在HTML檔裡嵌入SVG檔?

看板Ajax作者 (用了十年的暱稱要改一下!)時間16年前 (2009/03/25 11:05), 編輯推噓1(102)
留言3則, 1人參與, 最新討論串1/1
在一個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
稍微去查一下XML你就會知道什麼是CDATA
03/26 00:39, 1F

03/26 00:39, , 2F
另外我隨便google了一下 別人好像用text/ecmascript
03/26 00:39, 2F

03/26 00:39, , 3F
不曉得有沒有影響
03/26 00:39, 3F
文章代碼(AID): #19oPza4V (Ajax)
文章代碼(AID): #19oPza4V (Ajax)