Parsing the first image src of a list
I need to parse a value from an xml and place it to image's src field.
I tried parsing it as $(".photoBox img").append(ImageSmURL);
and I got
<img src="" alt="">/FLPM/media/images/0E7Q9Z0C_sm.jpg/FLPM/media/images/2A9L1V2X_sm.jpg</img>
how do I do it so the result will be as...
<img src="/FLPM/media/images/0E7Q9Z0C_sm.jpg" alt="" />
My xml
<Images>
<ImageID id="63">
<ImageSmURL>/FLPM/media/images/5V2G4Q5S_sm.jpg</ImageSmURL>
<ImageLgURL>/FLPM/media/images/5V2G4Q5S.jpg</ImageLgURL>
</ImageID>
<ImageID id="64">
<ImageSmURL>/FLPM/media/images/5Y2K4T5V_sm.jpg</ImageSmURL>
<ImageLgURL>/FLPM/media/images/5Y2K4T5V.jpg</ImageLgURL>
</Im开发者_运维百科ageID>
</Images>
You can do it this way:
$(".photoBox img").attr("src", ImageSmURL);
.append()
adds text/elements at the end of an element.
.attr()
sets the given attribute, in this case src
.
精彩评论