<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<input type="button" value="删除" id="btn">
</body>
<script>
var btn = document.getElementById('btn');
var div = document.createElement('div');
div.style.width = '150px';
div.style.height = '50px';
div.style.backgroundColor = 'pink';
div.style.margin = '200px auto';
div.innerText = '已删除';
div.style.textAlign = 'center';
div.style.lineHeight = '50px';
div.style.display = 'none';
document.body.appendChild(div);
btn.onclick = function () {
div.style.display = 'block';
setTimeout(function () {
div.style.display = 'none';
}, 3000);
};
// console.dir(document.body); // 不写document. 提示is not defined
</script>
</html>
原生js删除提示文本框(创建元素)隔一段时间后自动消失-setTimeout
最新推荐文章于 2023-10-25 13:48:39 发布