我有一堆A-links组织如下,
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
答案 0 :(得分:1)
$('.thumbnail_wrap > a:not([href^="photos/' + year + '"])').hide();
您需要在选择器
周围添加括号