在 jQuery 中使用 .not 函数和 .hover

发布于 2024-12-05 15:30:30 字数 271 浏览 3 评论 0原文

我正在尝试使用以下代码块,但不起作用。我需要使用悬停功能,但如果 div 有类 myclass,则不想显示样式 display: none

jQuery('.image').not('.myclass').hover( function()
{
     jQuery(this).find('.arrow').show();
}, function()
{
     jQuery(this).find('.arrow').hide();
});

I'm trying to use the following block of code, but is not working. I need to use the hover function, but do not want to show the style display: none if the div has a class myclass:

jQuery('.image').not('.myclass').hover( function()
{
     jQuery(this).find('.arrow').show();
}, function()
{
     jQuery(this).find('.arrow').hide();
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

小镇女孩 2024-12-12 15:30:30

您可以考虑使用 if 语句,而不是 not。类似

$('.image').mouseenter(function(){
    if($(this).hasClass('myclass')){
        $('.arrow').show();
    }    
});

$('.image').mouseleave(function(){
    if($(this).hasClass('myclass')){
        $('.arrow').hide();
    }    
});

示例: http://jsfiddle.net/ccB7K/2/

Instead of not, you might consider an if statement. Something like

$('.image').mouseenter(function(){
    if($(this).hasClass('myclass')){
        $('.arrow').show();
    }    
});

$('.image').mouseleave(function(){
    if($(this).hasClass('myclass')){
        $('.arrow').hide();
    }    
});

Example: http://jsfiddle.net/ccB7K/2/

沙沙粒小 2024-12-12 15:30:30

不要使用 .not,而是使用 JQuery 的 not CSS 样式选择器。

执行这里。 http://jsfiddle.net/CJp4A/

Instead of using .not, use JQuery's not CSS style selector instead.

Implementation here. http://jsfiddle.net/CJp4A/

山色无中 2024-12-12 15:30:30

您可以尝试这个

jQuery('.image:not(.myclass)')

http://api.jquery.com/not-selector/

You can try this

jQuery('.image:not(.myclass)')

http://api.jquery.com/not-selector/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文