2014-01-17 30 views

回答

0

您可以使用jQuery

如果你想要一個click事件添加到切片:

// this adds a click event to the first slice 
    $("path[data-id='s0']").click(function() { 
    alert('you clicked slice one'); 
    }); 

    // if you have multiple pie's you can be more specific 
    $("#svg svg path[data-id='s0']").click(function(){ 
    alert('you just clicked pie with id #svg'); 
    }); 
如果你想點擊事件添加到整個餅

$('#svg').click(function(e){ 
     alert('you just clicked the whole pie!'); 
    }); 
0

。 onclick應該被設置爲一個函數而不是一個字符串。嘗試

elemm.onclick =函數(){警報( '等等'); };

0

在您的pizza.js文件中,您可以在Snap.svg後添加一個onclick監聽器

pie : function (legend) { 
     // pie chart concept from JavaScript the 
     // Definitive Guide 6th edition by David Flanagan 
     ... 

     path.node.setAttribute('data-id', 's' + i); 

     //============= You could add your listener here 
     path.click(alert("My click function")); 
     //=============================================== 


     this.animate(path, cx, cy, settings); 

     // The next wedge begins where this one ends 
     start_angle = end_angle; 
     } 

    return [legend, svg.node]; 
}, 

另一種選擇是試圖通過事件{} @ pizza.js

添加新事件