简体   繁体   English

我想拥有可以搜索我的图像的链接

[英]I want to have links that can search through my images

I have "tags" on my webpage and once clicked you can see the corresponding image. 我的网页上有“标签”,单击后即可看到相应的图像。 Example: I click on the Dogs link and I see images of Dogs on my gallery. 示例:我单击“狗”链接,然后在图库中看到“狗”的图像。 Something like this: 像这样:

<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">

however, it doesn't work for me. 但是,它对我不起作用。 Would there be easier/ more affective ways of doing it? 会有更容易/更有情感的方式来做到这一点吗?

Check for empty value .. 检查空值..

 if($(this).attr('rel')) {

should be 应该

 if($(this).attr('rel') != '') {
        $('img').hide();
        $('.' + $(this).attr('rel')).show();
    }

Hide all images and then show only required images using class selector in jquery. 隐藏所有图像,然后使用jquery中的类选择器仅显示所需的图像。

$('#filter a').click(function() {
    if($(this).attr('rel')) {
        $('img').hide();
        $('img.'+$(this).attr("rel)).show();
    }

return false;
});​
$('#filter a').on('click', function() {
    var cat = $(this).attr('rel');
    if(cat.length) $('img').hide().filter('.'+cat).show();
});​

On clicking the anchor, get the category (shortened to "cat") from the anchor's rel attribute, then if the category has length , ie it's not empty, hide all images, then filter the images based on the class that matches the previous rel attribute, and show those images. 单击锚点后,从锚点的rel属性中获取类别(简称为“ cat”),然后,如果类别具有length ,即不为空,则隐藏所有图像,然后根据与上一个rel的类过滤图像属性,并显示这些图像。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 是否可以使用JSONP图片搜索API来让用户在我的网站上搜索图片? - Is there a JSONP image search API that I can use to have users search for images on my site? 如何使用搜索栏过滤我的bootstrap 4导航栏链接? - How can I filter my bootstrap 4 navbar links with a search bar? 如何扫描搜索结果页面上的链接,然后突出显示符合条件的项目,这样我就不必全部单击? - How can I scan the links from a search result page, and then highlight items that match a criteria, so that I don't have to click through them all? 通过链接进行JavaScript搜索 - Javascript search through links 我需要这些图片来链接我做错了什么? - I Need these images to have links what am I doing wrong? 我如何有一个搜索框,人们可以在其中搜索我站点内的页面? - How can I have a search box where people can search for pages within my site? 如何遍历以下充满图像的目录并将图像添加到我的 HTML 页面 - How can I iterate through the following directory full of images and add the images to my HTML page 有人能告诉我为什么当我的链接下面有一个 div 时我的链接不可点击吗? - Can someone tell me why my links aren't clickable when I have a div under it? 如何使链接在a:hover上显示一个透明小框? - How can I have my links display a little transparent box on a:hover? 我希望我的div中具有动画切换高度的链接是可点击的 - I want links inside my div with animated toggle height to be clickable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM