我需要此代码多次运行。它仅在我单击按钮以附加图像并单击按钮以删除它们时运行。第三次单击不会再次附加图像
<button class="" onclick="showImages(this,'100000,jpg','1111111.jpg','5');"></button>
<div id="5" class="">
... //when I run the function it appends the <img> tag here
</div>
function showImages(button, image1, image2, id) { //user clicks a button "show"
if (image2 == "") { //if there is only one image
$('#show' + id + '').append('<img class=\"one\" src=\"images/' + image1 + '\" />'); //creates a div with 1 image
button.onclick = function () { //clicks it second time
$('#show' + id + '').empty(); //removes the div with image
};
} else { //if there are 2 images
$('#show' + id + '').append('<img class=\"two\" src=\"images/' + image1 + '\" /><img src=\"images/' + image2 + '\" />'); //div with 2 images
button.onclick = function () { //...
$('#show' + id + '').empty(); //...
};
}
}