我已经阅读了与使用javascript创建svg相关的其他问题,并遵循了所有链接,但是我似乎无法让它正常工作。也许这里有人能发现我做错了什么。
编辑:我目前在文档主体中有一个id为'svgbasics'的div,我正在尝试使用从xml文档中检索到的值创建一个svg形状。
当我加载页面时,没有显示任何内容。
这是我的代码:
var questions = [];
for (j=0; j<arrayIds.length; j++)
{
$(xml).find("C[ID='" + arrayIds[j] + "']").each(function(){
questions[j] =
{
typ: $(this).attr('typ'),
width: $(this).find("I").attr('wid'),
height: $(this).find("I").attr('hei'),
x: $(this).find("I").attr('x'),
y: $(this).find("I").attr('x'),
baC: $(this).find("I").attr('baC'),
boC: $(this).find("I").attr('boC'),
boW: $(this).find("I").attr('boW')
}
if ($(this).attr('typ') == '3')
{
var shape = this.id;
var svg = $('#svgbasics').svg('get');
svg.rect(x($(this).find("I").attr('x')),
y($(this).find("I").attr('y')),
width($(this).find("I").attr('width')),
height($(this).find("I").attr('height')),
{fill: colours[$(this).find("I").attr('baC')]});
} else {
alert($(this).find("I").attr('x'));
}
});
}