2010-07-17 115 views

回答

10

试试这个选择:

a:not([id*=gallery], [class*=gallery]) 

这将选择不具有“画廊”其任id或其class atttribute值的每个a元素。

还是一个完整的ID或类名匹配:

a:not([id=gallery], [class~=gallery]) 

这将选择不具有“画廊”为ID或类名各a元素。

+0

+1是短了很多。 – Sarfraz 2010-07-17 22:12:17

+3

你也可以这样做:not([id * = gallery],[class * = gallery]) – joelpittet 2010-07-17 22:13:11

+0

@joelpittet:我想这是正确的答案,因为他正在寻找一个disjuction而不是一个连词。 – Gumbo 2010-07-17 22:14:54

1

一种方法是去是这样的:

$('a').each(function(){ 
    if ($(this).attr('class').indexOf('gallery') == -1 && $(this).attr('id').indexOf('gallery') == -1) { 
    // your code.... 
    } 
}); 
+0

这有点笨重,你应该使用.filter(function(){return(condition to match)})不是.each – joelpittet 2010-07-17 22:17:33

1

有jQuery的一个hasClass选择,你可以使用它。 试试这个。

支票类只

$('a').each(function(){ 
if (!$(this).hasClass('gallery')) 
    { 
     //code here 
    } 
}); 

或检查这两个class和id

$('a').each(function(){ 
if (!$(this).hasClass('gallery') && $(this).attr('id').indexOf('gallery') == -1) 
    { 
     //code here 
    } 
}); 
相关问题