سؤال

I use the jcanvas plugin for my 2d tagcloud research. I wish that I could paint several tags on canvas and each of them links to a different page. So, I need a for loop to show the tags, Here is my code.

 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);
      }
    });
 }

But it turns out every tags links to the same url, that is not the result I expect. Anyone here could help me ! thx a lot !!!

you can test it in here.

هل كانت مفيدة؟

المحلول

Add property id (or any other name) and change function.
...
font: "20pt 'Trebuchet MS', sans-serif",
id: i,
...
click: function(data) { window.open("http://www.google.com/?"+data.id); }

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top