jQuery“如果这个,如果那个"然后做这个 [英] Jquery "if this and if that" then do this

查看:80
本文介绍了jQuery“如果这个,如果那个"然后做这个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这应该很简单,但是对我来说不起作用.我想说:

This should be so simple, but it's not working for me. I want to say:

如果该类没有当前"类,并且正文类不等于"home",则执行此操作....

If this doesn't have the class "current" AND if the body class does not equal "home", then do this....

这是我正在尝试(除其他事项外)无济于事的方法.只有第一个有条件的作品.

Here is what I'm trying (among other things) to no avail. Only the first conditional works.

$(".nav1 > ul > li").mouseleave(function() {

    if ( (!$(this).hasClass("current")) || (!$(body).hasClass("home"))  ){
         $(this).find(".nav-overlay").show();   
    }

}); 

我做错了什么?谢谢!

更新清晰度:

当满足以下条件时,我只想显示".nav-overlay":

I only want to show ".nav-overlay" when the following conditions are true:

  1. 您不在首页上(body class ="home") 和
  2. .nav1> ul> li"类不等于当前"类
  1. You are not on the homepage (body class="home") AND
  2. The ".nav1 > ul > li" class does not equal "current"

推荐答案

尝试$("body")&&:

   if ( (!$(this).hasClass("current")) && (!$("body").hasClass("home"))  ){
    //...

或者这样,它更短:

   if ( !$(this).is(".current") && !$("body").is(".home")  ){
     //...

这篇关于jQuery“如果这个,如果那个"然后做这个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆