2011-10-19 66 views
1

如果目標沒有特定的類(如下所示),我該如何改變這個選擇器來調用我的函數?沒有類的href的jQuery選擇器

$('a[href^="#"]').live('click', navigation.smoothScroll); 

<a class="noscroll" href="#">My Link</a> 

像這樣(僞代碼):

if (!($this).hasClass('noscroll')) 
    ($this).live('click', navigation.smoothScroll); 

回答

2

您可以使用.not()

$('a[href^="#"]').not('.noscroll').live('click', navigation.smoothScroll); 
1

使用:not() selector

$('a[href^="#"]:not(.noscroll)').live('click', function() { 
    //your code here 
});