Javascript 在d3中,模糊事件仅在firefox中不起作用

Javascript 在d3中,模糊事件仅在firefox中不起作用,javascript,d3.js,Javascript,D3.js,我试图在d3中使用blur事件,它在chrome和safari浏览器中运行良好,但不幸的是,它在firefox中不起作用。 使用模糊的目的是在画布外单击后重置其他项目。 这个问题有解决办法吗 var宽度=500; var高度=400; var svg=d3。选择(“即”) .append('svg') .attr('width',width) .attr('height',height) .attr(“保存Aspectratio”、“xMinYMin满足”) .attr(“视图框”,“0 0”

我试图在d3中使用
blur
事件,它在chrome和safari浏览器中运行良好,但不幸的是,它在firefox中不起作用。 使用模糊的目的是在画布外单击后重置其他项目。
这个问题有解决办法吗

var宽度=500;
var高度=400;
var svg=d3。选择(“即”)
.append('svg')
.attr('width',width)
.attr('height',height)
.attr(“保存Aspectratio”、“xMinYMin满足”)
.attr(“视图框”,“0 0”+宽度+“”+高度)
.append('g');
var outer=svg.append('g')
.attr('transform','translate(“+width/2+”,“+height/2+”))
.attr('class','boundry');
var boundry=outer.append(“svg:circle”)
.attr(“r”,100)
.attr(“类别”、“主要家长”)
.attr('fill','red')
.attr('笔划',“黄色”)
.attr(“笔划宽度”,5);
d3.选择所有('.primary parent')。在('click',function()上{
警报(“点击事件触发”);
}).on(“模糊”,函数(){
警报(“触发模糊事件”);
});

我不喜欢这个解决方案,但是可以通过自己跟踪聚焦对象并通过在窗口对象上附加一个临时单击侦听器来移除聚焦来实现类似于您正在寻找的行为。因此,事件代码类似于:

var focused;
var setWindowClickListener = function(e) {
    if (e.target !== focusedElement) {
    focusedElement = null;
    window.removeEventListener('click', setWindowClickListener);
    alert('blur');
  }
};

d3.selectAll('.primary-parent')
.on('click', function() {
    alert('click');
    focusedElement = d3.event.target;
    window.addEventListener('click', setWindowClickListener);
});


当然,这并不理想,因为我们附加了一个任意事件侦听器,而这不适用于键盘模糊-模糊事件的基本功能。但是,它可能会对您起作用,需要进行一些调整。

在IE11中也不起作用。这似乎已经讨论过了。