2017-09-05 70 views
1

我有一大堆的安排如下A-鏈接,一個:沒有[^ HREF =「...‘(’不開始」運營商)不工作

div class="thumbnail_wrap"> 
    <a href="photos/2014/1.png">..</a> 
    <a href="photos/2014/2.png">..</a> 
    <a href="photos/2015/1.png">..</a> 
    <a href="photos/2016/1.png">..</a> 
    .. 
</div> 

,我需要選擇所有對應於某個鏈接一年中所含var year

alert('Year selected: ' + year + ' ' + 
     'Photos in this section: ' + 
     $('.thumbnail_wrap > a[href^="photos/' + year + '"]').length + ' ' + 
     'Photos NOT in this section: ' + 
     $('.thumbnail_wrap > a:not[href^="photos/' + year + '"]').length ); 

// Find all images with the "/photos/<YEAR>" URL and make them visible 
$('.thumbnail_wrap > a[href^="photos/' + year + '"]').show(); 
// Find all images with the wrong Year URL and make them hidden 
$('.thumbnail_wrap > a:not[href^="photos/' + year + '"]').hide(); 

第一個表達式總是工作。但a:not表達式不起作用。收到此錯誤,

TypeError: a is undefined jquery-1.10.2.js 
+3

'$(」 thumbnail_wrap> A:不使用(HREF^= 「照片/ '+年+'」] )')。hide();' – Manav

+0

Got it thx missing paren –

回答

1
$('.thumbnail_wrap > a:not([href^="photos/' + year + '"])').hide(); 

您需要添加括號選擇

+0

....謝謝.. –