JQuery hidden objects

前端 未结 4 533
夕颜
夕颜 2021-01-29 11:27

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

相关标签:
4条回答
  • 2021-01-29 11:39

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

    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.

    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');
            });
        });
    
    });​
    

    See http://jsfiddle.net/s7FXR/

    0 讨论(0)
  • 2021-01-29 11:48

    If you are hidden on the click, and the click will always hide both, you may have this as your script:

    $(document).ready (function() {
        $('#image1, #image2').click(function() {
          $('#image1, #image2').hide();
    
          $('#div').load('page.html', function() {
            alert('Load was performed.');
          });        
        });
    });​
    

    Are you sure you are returning a correct content from you 'page.html'?

    0 讨论(0)
  • 2021-01-29 11:58

    This code binds the same handler to the click event, which hides both images and loads the page:

    $(document).ready(function() {
        $('#image1, #image2').click(function() {
            $('#image1, #image2').hide();
            $('#div').load('page.html');        
        });
    });​
    

    As mentioned in the comments you could devise a way of selecting all the related images. For example wrapping them in a div or adding a class to identify them.

    Take a look at this and this fiddle for an example on how to do this.

    Hope it helps.

    0 讨论(0)
  • 2021-01-29 12:00

    I think this is what you want:

    $(document).ready (function() {
        $('#image1').click(function() {
            $(this).hide('slow');
            $('#image2').hide('slow');
    
            $('#div').load(page.html');
        });
    });
    
    0 讨论(0)
提交回复
热议问题