Jquery 如何在<;中显示SVG内容;img>;镀铬标签
我正在使用一个JSF应用程序,并使用jQuery设计了一个内部方案编辑器。加载页面时,我需要从数据库调用XML内容,然后将给定的XML内容转换为SVG格式,并将其显示在Jquery 如何在<;中显示SVG内容;img>;镀铬标签,jquery,image,jsf,svg,Jquery,Image,Jsf,Svg,我正在使用一个JSF应用程序,并使用jQuery设计了一个内部方案编辑器。加载页面时,我需要从数据库调用XML内容,然后将给定的XML内容转换为SVG格式,并将其显示在img标记中。当我尝试将其转换为JPEG格式时,我也能做同样的事情,但当我转换为svg SVGmat时,数据会被提取出来,但不会显示在img标记中。我的应用程序使用Google Chrome。代码片段如下所示 function initImportImages() { createImage("image/svg", ap
img
标记中。当我尝试将其转换为JPEG格式时,我也能做同样的事情,但当我转换为svg SVGmat时,数据会被提取出来,但不会显示在img
标记中。我的应用程序使用Google Chrome。代码片段如下所示
function initImportImages() {
createImage("image/svg", applySvg);
}
//Export the image
function createImage(imageType, callback) {
var exporter = createExporter(imageType);
var value = $("#moleculeTxt").val();
exporter.render($("#moleculeTxt").val()).then(callback, alert);
}
function applySvg(svg) {
alert(svg);
$("#imageContainer").html(svg);
$("#image").html(svg);
$("#imageContainer").css("display", "inline-block");
}
//default functions of marvin to render the DB value back to image
function createExporter(imageType) {
var inputFormat ="mrv";
if(inputFormat == "") {
inputFormat = null;
}
var defaultServices = getDefaultServices();
var services = {};
services['molconvertws'] = defaultServices['molconvertws'];
var settings = marvinSketcherInstance.getDisplaySettings();
settings = {
'width' : parseInt($("#image").val(), 600),
'height' : parseInt($("#image").val(), 600)
/* 'width' : parseInt($("#image").val(), 600),
'height' : parseInt($("#image").val(), 600) */
};
var params = {
'imageType': imageType,
'inputFormat': inputFormat,// type of output image
'services': services, // to resolve any molecule format and be able to calculate stereo info
'settings': settings
}
try {
return new marvin.ImageExporter(params);
} catch(err) {
alert(err);
}
}
XHTML:
<h:form id="form1">
<s:div id="imageContainer">
<img id="image" class="bordered"></img>
</s:div>
</h:form>
为什么是jsf标记而不是seam标记?当您将s:div
更改为div
时,它是否工作?很可能不是。因此与jsf无关。你是说它在FireFox中可以工作?如果没有,请删除chrome标记以显示SVG的样子?您确定它有效吗?SVG是一个源,它是一个需要转换为字符串的数据,在标记中以SVG格式显示。为什么是jsf标记而不是seam标记?当您将s:div
更改为div
时,它是否工作?很可能不是。因此与jsf无关。你是说它在FireFox中可以工作?如果没有,请删除chrome标记以显示SVG的样子?您确定它有效吗?SVG是一个源,它是一个需要转换为字符串的数据,在标记中以SVG格式显示。