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));
}
精彩评论