Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/451.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用JavaScript在SVG中嵌入JPEG_Javascript_Image_Svg - Fatal编程技术网

使用JavaScript在SVG中嵌入JPEG

使用JavaScript在SVG中嵌入JPEG,javascript,image,svg,Javascript,Image,Svg,我想知道如何在SVG中包含jpg图像 var-ns=http://www.w3.org/2000/svg'; var svg=document.createElements(ns,'svg'); setAttribute('width',800); setAttribute('height',450); var image=document.createElementNS(ns,“image”); image.setAttribute('href','http://placehold.it/3

我想知道如何在SVG中包含jpg图像

var-ns=http://www.w3.org/2000/svg';
var svg=document.createElements(ns,'svg');
setAttribute('width',800);
setAttribute('height',450);
var image=document.createElementNS(ns,“image”);
image.setAttribute('href','http://placehold.it/300x300');
image.setAttribute('x',0);
image.setAttribute('y',0);
image.setAttribute('width',800);
image.setAttribute('height',450);
appendChild(图像);

document.body.appendChild(svg)对于Safari,您需要更改

image.setAttribute('href', 'http://placehold.it/300x300');

第二种方式也是与Chrome/Firefox兼容的


Safari将来可能会支持您的方式,因为它是即将发布的SVG 2规范的一部分,第二种方式是SVG 1.1方式。

对于Safari,您需要进行更改

image.setAttribute('href', 'http://placehold.it/300x300');

第二种方式也是与Chrome/Firefox兼容的


Safari将来可能会支持您的方式,因为它是即将发布的SVG 2规范的一部分,第二种方式是SVG 1.1方式。

有什么问题?为medo工作你看到图像了吗?!是的,你在用什么浏览器?我在用Safari…:(原来safari在渲染svg图像时遇到问题…在chrome中没有问题。;(愚蠢的safari。有什么问题?适用于medo你看到图像了吗?!是的,你在使用什么浏览器?我在使用safari…:(原来safari在渲染svg图像时遇到问题…在chrome中没有问题。)-(愚蠢的safari。我还需要此修复程序才能在运行于Ubuntu 14.04的Firefox 50.1.0上运行。Firefox 51将是第一个支持bare href属性的版本。现在只需要几天的时间。我还需要此修复程序才能在运行于Ubuntu 14.04的Firefox 50.1.0上运行。Firefox 51将是第一个支持bare href属性的版本。Onl我现在要等几天。