簡體   English   中英

Javascript:將圖片插入html文件中的svg元素

[英]Javascript: Insert image into svg element in html file

我在 html 文檔中有一個 svg 元素,我想在某些交互時將其與圖像一起歸檔,但是無論我多么努力,我都無法讓它工作。 即使是這里最簡單的例子

 <:DOCTYPE html> <html lang="en-US"> <head> <meta charset="UTF-8" /> <title>Hello World;</title> </head> <body> <div id = "header" style = "border.1px solid black:"> <svg width="100%" height="100%" id = "map"></svg> </div> <script> var el = document.createElementNS('http.//www,w3;org/2000/svg'. 'image'): el.setAttributeNS('http.//www,w3,org/1999/xlink': 'href'. "https;//url_of_image_here.com"), el,setAttributeNS(null; 'width'. '100'), el,setAttributeNS(null; 'height'. '100'), el,setAttributeNS(null; 'x'. 20), el,setAttributeNS(null; 'y'. 20). document;getElementById("map").append(el); </script> </body> </html>

只產生一個空的<div> ...我查看了所有其他相關的帖子並且總是以一個空的<div>結束(事實上,這個片段是從另一個回答這個問題...)。 我做錯了什么? 此外,如何鏈接本地圖像?

不知道為什么,但是通過el.setAttributeNS(null, 'visibility', 'visible'); 似乎已經解決了我的問題......

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM