2014-05-03 41 views
2

當onerror被觸發時,如何隱藏svg:圖像?d3設置圖像可見性=隱藏onerror

node.append('svg:image') 
    .attr("x", "-30px") 
    .attr("y", "-40px") 
    .attr("width", "60px") 
    .attr("height", "80px") 
    .attr("xlink:href", function(d){ 
     return 'https://somedomain.com/images/' + d.name; 
    }) 
    .attr("onerror", function(d){ 
     console.log('The image ' + d.name + ' failed to load'); 
     // this.style("visibility", "hidden"); 
     // d.style("visibility", "hidden"); 
    }); 

回答

3

根據您的描述,代碼會是這個樣子:

.on("error", function() { 
    d3.select(this).style("visibility", "hidden"); 
}); 

這是假設的元素,你要隱藏的火災error事件。

相關問題