我的简单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.
这是我的Js代码:
$("#oferty.col-md-4") .mouseover(function () { //$(this).css("backgroundColor", "yellow"); modifyPoint($(this).attr("data-name")) });
我想我的选择器有问题.谁能告诉我如何修改它?
您需要使用mouseenter,来自子元素的mouseover将传播到父元素
$("#oferty.col-md-4").mouseenter(function () { //$(this).css("backgroundColor", "yellow"); modifyPoint($(this).attr("data-name")) })
MDN:mouseenter
与鼠标悬停类似,它的不同之处在于它不会冒泡,并且当指针从其后代的物理空间之一移动到其自己的物理空间时,它不会被发送.