javascript - Jquery hasClass 显示

标签 javascript jquery

我即将使用 jquery 在 drupal 中制作一个菜单,我需要当它具有事件类时需要显示的链接。

(function ($) {
 $(document).ready(function() {
  $('.region-sidebar-first .block-menu ul.menu').children('li').children('a').hasClass('active').hide();
  $('.region-sidebar-first .block-menu h2').click(function() {
   $(this).parent().siblings().children().next().children().slideUp(400);           
   $(this).next('.content').children('.menu').slideDown(400);
  });
 });
}(jQuery));

最佳答案

你需要使用jquery hasClass()

完整信息在这里:http://api.jquery.com/hasClass/

if ($('#item1').hasClass("active")) {
 DoSomething()
} else { 
 DoSomethingElse()
}

您还可以使用:visible

if ($('#item1:visible')) {
     DoSomething()
    } else { 
     DoSomethingElse()
    }

关于javascript - Jquery hasClass 显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7964730/

相关文章:

javascript - 插入和选择时如何获取查询结果的数量?

javascript - 是否应使用 encodeURIComponent 对 post ajax 请求的参数进行编码?

javascript - 鼠标打开/鼠标关闭(悬停)问题

jQuery 拖动时获取上一个和下一个元素

jQuery - 检测 <video> onEnded

javascript - 如何从 flash as3 获取文本和矩形颜色?

javascript - jQuery 滑动一个 div

javascript - 切换 jQuery 动画不起作用

php - 我可以在 PHP 中等待 js 进程后再继续吗?

javascript - 大于在小于 100 的数字上返回错误值。Javascript