开发者

How can I append an Image using a jquery function with 1 param?

How can I append an Image using a jquery function with 1 param?开发者_如何学编程

function imageadd(param1){
    $('#random').append(...)
}

with the src being src="gallery/param1.jpg"


function imageadd(param1)
{
    $('#random').append("<img src='gallery/" + param1 + ".jpg'");
}


Create a new img element and assign the src attribute. Aassuming param1 was the src you could do it like this:

function imageadd(param1){
    $('#random').append($('<img />').attr('src','gallery/' + param1 + '.jpg'));
}

or, if param1 is the full url already:

function imageadd(param1){
    $('#random').append($('<img />').attr('src', param1));
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜