简体   繁体   中英

Image src not working in jquery

i have a function,

function showimage(a)
    {
        $("#lightboxholder").show("fast");
        $('#lightboximage').attr('src', 'images/demo/190x90.gif');
    }

when i go to localhost/svce and view in gallery.php, it doesnt show me the image, however if i replace $('#lightboximage').attr('src', 'images/demo/190x90.gif'); by $('#lightboximage').attr('src', 'http://localhost/svce/images/demo/190x90.gif'); then it shows me the image, sorry for my bad english, thanks

Try

function showimage(a)
{
       $("#lightboxholder").show("fast");
       $('#lightboximage').attr('src', '../images/demo/190x90.gif');
}

Note the "/" before images/demo....

The problem is relative url - it's always a challenge for me too

Try these

$('#lightboximage').attr('src', '../images/demo/190x90.gif');

or

$('#lightboximage').attr('src', '../../images/demo/190x90.gif');

As you move from page to page, relative url will change, but absolute won't

You're changing the src to a relative URL. So if your current page is http://localhost/foo/bar , the browser will try to find the image at http://localhost/foo/bar/images/demo/190x90.gif . Use an absolute URL, like /svce/images/demo/190x90.gif .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM