Event.target.id在firefox中不起作用

event.target.id not working in firefox

本文关键字:不起作用 firefox target id Event      更新时间:2023-09-26

我有一个脚本,每次用户将鼠标悬停在我的一个页面按钮上时都会运行该脚本。这在safari和chrome中工作得很好,但在firefox中,event.target.id被返回null,因此我的脚本的其余部分无法运行。起初我认为这是mouseenter的问题,但我向我的函数添加了一个警报,它被触发了,所以它被触发了。控制台显示event.target.id为空,这就是问题所在。

谁有解决办法?这将获取用户悬停在其上的按钮的id,并将页面主体设置为与按钮id具有相同类的隐藏div的html。

$(".label").mouseenter(function(){
   var hover=(event.target.id);
   $('.centercover').fadeIn(400)
   var filler= $('.'+hover).html();
   ....rest of script for fadding in new content...
   }
$(".label").on('mouseenter', function(event){ //pass the parameter
   var hover = event.target.id;
   $('.centercover').fadeIn(400)
   var filler = $('.' + hover).html();
});