可能对您来说很容易,但是我做不到。 我需要在5秒钟后显示div,并在显示后等待5秒钟并隐藏它。我该怎么办?
答案 0 :(得分:1)
setTimeout(function () {
document.getElementById('samplediv').style.display='none';
setTimeout(function () {
document.getElementById('samplediv').style.display='block';
}, 5000);
}, 5000);
答案 1 :(得分:1)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<div id="myDiv" hidden>Your Div</div>
</body>
<script>
var myDiv = document.getElementById("myDiv");
setTimeout(function(){
myDiv.style.display="block";
console.log("Showing");
setTimeout(function(){
console.log("Hiding");
myDiv.style.display="none";
},10000);
},5000);
</script>
</html>