0
我已經閱讀了其他與使用JavaScript創建SVG相關的問題,並且關注了任何鏈接,但我似乎無法得到它的工作。也許這裏有人可以發現我要出錯的地方。使用JavaScript努力創建SVG形狀
編輯:我目前有一個與ID'svgbasics'在文檔正文的div,我試圖使用我從XML文檔中檢索到的值創建一個SVG形狀。
當我加載頁面時,什麼都不顯示。
這裏是我的代碼:
var questions = [];
for (j=0; j<arrayIds.length; j++)
{
$(xml).find("C[ID='" + arrayIds[j] + "']").each(function(){
// pass values
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 {
// Add here
alert($(this).find("I").attr('x'));
}
});
}
如果您已經使用JavaScript,難道不會更容易使用
我選擇使用SVG的原因是因爲我打算使用SVG形狀來構建一個UI,並且從我的理解來看,SVG是比Canvas更好的事件處理選擇。 – 2010-06-04 12:07:38