开发者

jquery Show and Hide the picture by number of question?

开发者 https://www.devze.com 2023-03-02 20:10 出处:网络
Hey I have 10 ten image in a div(name is background).. and display properties is none.. I want toshow by questions number..I mean Question=1 img1.hide(),img2.show() Question=2 img2.hide(); img3.show

Hey I have 10 ten image in a div(name is background).. and display properties is none..

I want to show by questions number.. I mean Question=1 img1.hide(),img2.show() Question=2 img2.hide(); img3.show ............ question 10 img9开发者_StackOverflow中文版.hide() img10.show

my function name is resim() and it callback from Button click

function resim(question) This is wrong right :) Actually this is wrong.. it doesn't work :))

var i=0;
while (i<3)
{
    if (question==i)
    {
        $("#background img").eq(i-1).hide();
        $("#background img").eq(i).show();
        i++;
    }
    else
    {
        return;
    }
}

but I cant do the function... How must it be? Sorry about my english


For Question 1 you want to show the first image and so on? question parameter is the Number of the question? first hide all images, then show the image (question number minus 1 - index 0 based).

function resim(question) {
    // hide all
    $("#background img").hide();
    // show by Num
    $("#background img").eq(question-1).show();
}

Be sure the div background has display: block and not none.


If the div#background contains all your img tags and div#background is set to display:none; then even if you set the images to show, they won't display because their parent element is set not to display.

You'll have to set the div#background to show and the individual img tags to hide and show the individual images as needed.

An alternate function you may want use could look like this:

function resim(question)
{
    $("#background img").hide();
    $("#background img:eq("+question+")").show();
}
0

精彩评论

暂无评论...
验证码 换一张
取 消