在這裏,我打電話給文本和圖像附加到div的JavaScript函數,現在我想在2秒後隱藏div。我怎樣才能做到這一點?如何使用超時隱藏div?
代碼:
function showdiv(city, imagesrc, timeout) {
window.setTimeout(function() {
document.getElementById('city-order').innerHTML = "";
document.getElementById('order-product').innerHTML = "";
document.getElementById('product-list-display').style.display = "block";
var order_placed_city = document.getElementById('city-order');
var content = document.createTextNode(city);
order_placed_city.appendChild(content);
var product_order = document.getElementById('order-product');
var elem = document.createElement("img");
product_order.appendChild(elem);
elem.src = imagesrc;
},timeout);
document.getElementById('product-list-display').style.display = "none";
}
'showdiv( '城市',「http://placehold.it/200x200',2000)' - 也許? – TryingToImprove