Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/424.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript d3 onerror带有html工具提示标记的默认图像_Javascript_Html_Image_D3.js_Onerror - Fatal编程技术网

Javascript d3 onerror带有html工具提示标记的默认图像

Javascript d3 onerror带有html工具提示标记的默认图像,javascript,html,image,d3.js,onerror,Javascript,Html,Image,D3.js,Onerror,我正在为D3项目中的鼠标悬停事件制作带有图像和其他数据的工具提示。我想在缺少数据图像时使用默认图像。我无法让OneRor处理我编写的html字符串,如果有人能帮我看一下,我将不胜感激。我想我的问题是这个字符串的格式 这是相关的代码位: .on("mouseover", function(d) { d3.select(this) .transition() .duration(50) div.transition() .duration(200) .

我正在为D3项目中的鼠标悬停事件制作带有图像和其他数据的工具提示。我想在缺少数据图像时使用默认图像。我无法让OneRor处理我编写的html字符串,如果有人能帮我看一下,我将不胜感激。我想我的问题是这个字符串的格式

这是相关的代码位:

.on("mouseover", function(d) {
  d3.select(this)
    .transition()
    .duration(50)
  div.transition()
      .duration(200)
      .style("opacity", .9);

  div.html('<img src="images/'+ d.properties.objectNumber +'.jpg" onError="this.onerror=null;this.src="images/00037631.jpg" style ="width:4em;" /> &nbsp;' + d.properties.name)

    //div.html('<img src="images/'+ d.properties.objectNumber +'.jpg" onError="this.src="images/ANMS0533[020].jpg" style ="width:4em;" /> &nbsp;' + d.properties.name)
    .style("left", (d3.event.pageX) + "px")
  .style("top", (d3.event.pageY - 28) + "px");
})
.on(“鼠标悬停”,函数(d){
d3.选择(本)
.transition()
.期限(50)
过渡部()
.持续时间(200)
.样式(“不透明度”,.9);
div.html(“”+d.properties.name)
//div.html(“”+d.properties.name)
.style(“左”,“d3.event.pageX)+“px”)
.style(“top”,(d3.event.pageY-28)+“px”);
})
我的图像在它存在的地方显示得很好,但是如果图像丢失,我会得到一个无图像图标,我希望看到一个默认图像,或者什么都没有


我希望有人能帮上忙。

我可能会像这样解决这个问题,在上传的img标签上使用
id
class
,然后使用d3选择它,并在错误事件后附加它

.on(“鼠标悬停”,函数(d){
d3.选择(本)
.transition()
.期限(50)
过渡部()
.持续时间(200)
.样式(“不透明度”,.9);
div.html(“”+d.properties.name)
d3.在(“错误”,函数()上选择(“#加载pic”){
设el=d3。选择(此);
el.attr(“src”、“images/00037631.jpg”).style(“width”、“4em”);
el.on(“错误”,空);
})
//div.html(“”+d.properties.name)
.style(“左”,“d3.event.pageX)+“px”)
.style(“top”,(d3.event.pageY-28)+“px”);

})
我可能会像这样解决这个问题,在上传的img标签上使用
id
class
,然后使用d3选择它并附加错误事件

.on(“鼠标悬停”,函数(d){
d3.选择(本)
.transition()
.期限(50)
过渡部()
.持续时间(200)
.样式(“不透明度”,.9);
div.html(“”+d.properties.name)
d3.在(“错误”,函数()上选择(“#加载pic”){
设el=d3。选择(此);
el.attr(“src”、“images/00037631.jpg”).style(“width”、“4em”);
el.on(“错误”,空);
})
//div.html(“”+d.properties.name)
.style(“左”,“d3.event.pageX)+“px”)
.style(“top”,(d3.event.pageY-28)+“px”);

})
这可能是由于
onError
需要函数引起的。感谢您的回复。所以我不能像这样在html中使用on error?我不知道如何在这里使用函数。您是否能够帮助我编写示例代码,或者为我指出一个可以提供帮助的资源?再次感谢您不厌其烦地回复。这可能是由于
onError
需要函数造成的。感谢您的回复。所以我不能像这样在html中使用on error?我不知道如何在这里使用函数。您是否能够帮助我编写示例代码,或者为我指出一个可以提供帮助的资源?再次感谢您不厌其烦地回复。非常感谢您的帮助。这个解决方案对我非常有效。我写函数的尝试没有取得任何进展,所以我非常感谢你的帮助。非常感谢你的帮助。这个解决方案对我非常有效。我尝试编写函数,但没有成功,因此我非常感谢您的帮助。