jquery“或”声明

时间:2010-08-10 14:37:32

标签: jquery

我如何在jquery中使用“或”语句,我有两个单独的语句,我认为我可以合并为一个:

$('li.members').hover(function() {
    $('.members-show').show();
    $('.brokers-show').hide();
    $('.providers-show').hide();
    $('.employers-show').hide();
    $('.seniors-show').hide();
    return false;
  });

$('li.members-active').hover(function() {
    $('.members-show').show();
    $('.brokers-show').hide();
    $('.providers-show').hide();
    $('.employers-show').hide();
    $('.seniors-show').hide();
    return false;
  });

4 个答案:

答案 0 :(得分:16)

$('li.members, li.members-active').hover(function() {
    $('.members-show').show();
    $('.brokers-show').hide();
    $('.providers-show').hide();
    $('.employers-show').hide();
    $('.seniors-show').hide();
    return false;
  });

答案 1 :(得分:10)

$('li.members, li.members-active').hover(function() {
    $('.members-show').show();
    $('.members-show, .providers-show, .employers-show, .seniors-show').hide();    
    return false;
  });

答案 2 :(得分:1)

我认为您可以使用Multiple Selector

答案 3 :(得分:1)

试试Multiple Selector

$('li.members,li.members-active').hover(function() {
    $('.members-show').show();
    $('.brokers-show').hide();
    $('.providers-show').hide();
    $('.employers-show').hide();
    $('.seniors-show').hide();
    return false;
  });