如果在触发错误时如何隐藏svg:image?
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");
});
答案 0 :(得分:4)
根据您的描述,代码看起来像这样:
.on("error", function() {
d3.select(this).style("visibility", "hidden");
});
假设您要隐藏的元素触发error
个事件。