鼠标悬停的函数调用太多

 法华大道暴力喵一只 发布于 2023-02-09 11:44

我的简单js代码有点问题.对于我来说未知的原因,它多次调用函数.如果用鼠标悬停在div上,那么它应该是函数1次.相反,如果我每次将鼠标移动到div中的某些内容时调用都会起作用.这是我的代码:

Get more libraries

NuGet is a free Visual Studio extension that makes it easy to add, remove, and update libraries and tools in Visual Studio projects.

Learn more »

这是我的Js代码:

$("#oferty.col-md-4")
     .mouseover(function () {
        //$(this).css("backgroundColor", "yellow");
        modifyPoint($(this).attr("data-name"))      
 });

我想我的选择器有问题.谁能告诉我如何修改它?

1 个回答
  • 您需要使用mouseenter,来自子元素的mouseover将传播到父元素

    $("#oferty.col-md-4").mouseenter(function () {
        //$(this).css("backgroundColor", "yellow");
        modifyPoint($(this).attr("data-name"))
    })
    

    MDN:mouseenter

    与鼠标悬停类似,它的不同之处在于它不会冒泡,并且当指针从其后代的物理空间之一移动到其自己的物理空间时,它不会被发送.

    2023-02-09 11:45 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有