2012-10-17 21 views
2

我使用jcanvas插件進行了我的2d tagcloud研究。 我希望我可以在畫布上畫幾個標籤,並且每個標籤都鏈接到不同的頁面。 所以,我需要一個for循環來顯示標籤, 這是我的代碼。html5 jcanvas點擊功能用於「for」循環出錯

for(i=1;i<=5;i++){ 

    $("canvas").drawText({ 
     layer: true, 
     fillStyle: "#9cf", 
     strokeStyle: "#000", 
     strokeWidth: 1, 
     x: 100, y: 30*i, 
     text: "tag"+i, 
     font: "20pt 'Trebuchet MS', sans-serif", 

     // Event bindings 
     mouseover: function() { 
     $("canvas").css({cursor: "pointer"}); 
     }, 
     mouseout: function() { 
     $("canvas").css({cursor: "default"}); 
     }, 
     // Click link to open it 
     click: function(layer) { 
     window.open("http://www.google.com/?"+i); 
     } 
    }); 
} 

但事實證明,每一個標籤鏈接到相同的URL,這是沒有結果的我希望。 這裏的任何人都可以幫助我!多謝 !!!

你可以在here進行測試。

回答

1

添加屬性ID(或任何其他名稱)和更改功能。
...
font: "20pt 'Trebuchet MS', sans-serif",
id: i,
...
click: function(data) { window.open("http://www.google.com/?"+data.id); }

+0

THX!它運作良好! – berryrandy