JQuery MouseEnter

编程入门 行业动态 更新时间:2024-10-28 00:28:27
JQuery MouseEnter - 仅针对没有特定类的元素触发(JQuery MouseEnter - Trigger only for element that has not specific class)

我在类上使用mouseenter,但如果该类有另一个类,则不应触发mouseenter方法。 我厌倦了下面的代码,但由于某种原因我没有得到它不起作用。 任何想法为什么,也许一些建议?

$(".someClass:not('.someOtherClass')").mouseenter(function(){ //some code });

I use mouseenter on a class but if that class has another class the mouseenter method should not be triggered. I tired the below code but for some reason I do not get it is not working. Any ideas why and maybe some suggestions?

$(".someClass:not('.someOtherClass')").mouseenter(function(){ //some code });

最满意答案

这段代码在someClass的输入时触发如果鼠标没有someOtherClass类,它将执行//执行此代码。

$(".someClass").mouseenter(function(e){ if (!$(e.target).hasClass('someOtherClass')){ // do this } });

This piece of code triggers on enter of someClass If the mouse does not have a class of someOtherClass it will execute the //do this code.

$(".someClass").mouseenter(function(e){ if (!$(e.target).hasClass('someOtherClass')){ // do this } });

更多推荐

本文发布于:2023-08-05 12:44:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1432311.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:JQuery   MouseEnter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!