我的网页上有“标签”,点击后您可以看到相应的图像。示例:我单击“狗”链接,然后在我的画廊中看到狗的图像。像这样的事情:
<a href="#" rel="dog">Show Dogs</a>
<script>
$('#filter a').click(function() {
if($(this).attr('rel')) {
$('img').hide().filter('[class="' + $(this).attr('rel') + '"]').show();
$('img').show();
}
return false;
});
<img src="http://www.petliferadio.com/doggydog.jpg" class="dog">
但是,这对我不起作用。是否有更简单/更有效的方式来做到这一点?
最佳答案
检查空值..
if($(this).attr('rel')) {
应该是
if($(this).attr('rel') != '') {
$('img').hide();
$('.' + $(this).attr('rel')).show();
}
关于javascript - 我想要有可以搜索我的图像的链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13202264/