0

如何挂钩几个 div 以悬停?我使用add()但它不起作用。

var h1 = $('.a');
var h2 = $('.b');
var h3 = $('.c');
var all = h1.add(h2).add(h3);

all.stop(true, true).hover(function(){// not work
    var this_id = $(this).filter('.a').attr('id');
    // do something
}, function(){
    ...
});
4

3 回答 3

2

你可以做

$('.a, .b, .c').hover()
于 2013-06-05T03:59:55.413 回答
1

你可以分开使用,

$('.a, .b, .c').hover(function(){
  ......
});

或者

 var all = $('.a, .b, .c');

 $(all).hover(function(){
  ......
});
于 2013-06-05T04:01:37.527 回答
0

我明白了,因为var this_id = $(this).filter('.a').attr('id');应该更改为$(this).attr('id')
Thanks for all answer让我确定 add() 正在工作!!!

于 2013-06-05T04:26:08.760 回答