单击事件在svg路径上不起作用

Click event is not working on svg path

本文关键字:不起作用 路径 svg 事件 单击      更新时间:2023-09-26

嗨,我正在处理一些东西,我正在使用svg路径,但svg的点击事件不起作用

  $path.map(function(){
    $(this).mouseenter(function(){
        $count = $path.attr('data-like');
        $('#counter').text($count);
        $('#tool').addClass('active');
    });
    $(this).mousemove(function(e){
        $('#tool').css({'top': e.pageY + -14,'left': e.pageX + -14});
    });
    $(this).mouseleave(function(){
        $('#tool').removeClass('active');
    });
    $(this).click(function(){
        console.log('click');
    });

  });

为什么它不起作用?

编辑:当我在mouseenter函数中出错时,奇怪的点击函数开始工作。

尝试使用on事件处理程序:

 $path.map(function(){
    $(this).mouseenter(function(){
        $count = $path.attr('data-like');
        $('#counter').text($count);
        $('#tool').addClass('active');
    });
    $(this).mousemove(function(e){
        $('#tool').css({'top': e.pageY + -14,'left': e.pageX + -14});
    });
    $(this).mouseleave(function(){
        $('#tool').removeClass('active');
    });
    $(this).on("click", function(){
        console.log('click');
    });

  });

我使用了mouseup而不是click函数,它现在正在中工作