简体   繁体   中英

How to display an image from XML in jQuery mobile?

I feel like this has a very simple solution, but I am trying to get this to work for probably too long now.

I've made a function to render an image, atleast that's what it's supposed to do, but it doesn't.

function renderAD(entries) {
    var o = '';
    $.each(entries, function(i, v) {
        o +="<img src=" +v.image +"/>";
    });
    $("#adplace").html(o);    
}

I checked that v.image refers to http://allroundcars.nl/logo-ijsselmondenieuws.png , which is the image I want to load. But all I see is a '?' image '?' image (image not found).

What am I doing wrong? Any help is appreciated,

Thanks

Try replacing your each with:

$(entries).each(function(i, v) {
    o +='<img src="' + v.image + '"/>';
});

Update: to add an <a> around it:

o +='<a href="' + v.link + '"><img src="' + v.image + '"/></a>';

Here's a working version:

function renderAD(entries) {
    var o = '';
    $(entries).each(function(i, v) {
        o +="<img src=\"" + v.image +"\"/>";
    });
    $("#adplace").html(o);    
}

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