jQuery隐藏对象 [英] JQuery hidden objects

查看:119
本文介绍了jQuery隐藏对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我已经编辑了问题,以便您理解.我在段落中有10张图片及其各自的名称.因此,您有10个图像和10个段落.由于图像不同,并且当然具有不同的名称,因此我不能使用类.因此,我在一个图像上使用了一个ID,在其名称上使用了另一个ID.

Ok guys, I have edited the question so that you can understand. I have 10 images and their respective name in paragraph. So, you have 10 images and 10 paragraphs. As the images are different, and of course, have different names, I cannot use a class. So, I used an ID to one image and another ID to its name.

用户将单击一张图像,该图像也将隐藏起来,并分别显示其名称.当用户单击另一个图像时,它将再次隐藏及其相应的名称,直到所有内容都被隐藏为止.我可以为一个图像及其相应的名称使用一个类,但是用户有权仅单击图像而不单击名称.就像一个隐藏的物体游戏!

The user will click on one image, it wil hide and its respective name as well. When the user will click another image, it will hide and its respective name again until everything is hidden. I could use a class for one image and its respective name, but the user has the right to click only on the image and not on the name. Just like a hidden object game!

下面我将为您提供一张图片的示例:

I will give you an example of one image below:

$(document).ready(function() {
    $('#image1').click(function() {
        $(this).hide('slow');
        $('#name').hide('slow');
    });

    if ($('#image1').is(':hidden')) {
        alert('Hello');
    }
});​

请记住,我更改了示例,以便您可以理解.如您所见,如果用户单击图像,则其相应名称也将被隐藏.他们两个都是隐藏的.然后,我确认图像是否隐藏,将显示一个警告框.该图像及其名称确实隐藏了,但是警报框未显示...而且我必须验证该图像是否隐藏,以便显示警报框.

Bear in mind, I changed the example so that you can understand. As you see, if the user is clicking on image, its respective name also is hidden. Both of them are hidden. Then, I verify if the image is hidden, an alert box will display. The image and its name do hide, but the alert box is not displaying... And I have to verify if the image is hidden, so that the alert box is displayed.

推荐答案

如果我正确理解了您的问题,您的代码应该是类似的东西.

Your code should be something like that if i correctly understand your question.

因此,如果我明白了,您可以做类似的事情,假设您向要检查的所有图像添加了一个类(让我说myimgclass):

So, if i get it, you can do something like that, assuming you add a class (lets say myimgclass) to all your images you want to check:

如果我正确理解您的问题,您的代码应为类似代码.

Your code should be something like that if i correctly understand your question.

因此,如果我明白了,您可以做类似的事情,假设您向要检查的所有图像添加了一个类(让我说myimgclass):

So, if i get it, you can do something like that, assuming you add a class (lets say myimgclass) to all your images you want to check:

$(document).ready(function() {
    $('.myimgclass').click(function() {
        //hide >>name here<<

        $(this).hide('slow', function() {
            var check = true;
            $('.myimgclass').each(function() {                
                //we check if image is visible, if so we stop here
                if($(this).is(':visible')) {
                    check = false;
                    return;
                }
            });
            if(check) alert('Hello');
        });
    });

});​

请参见 http://jsfiddle.net/s7FXR/​​

这篇关于jQuery隐藏对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆