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 } });更多推荐
发布评论