【发布时间】:2019-03-27 20:18:09
【问题描述】:
所以我尝试做一个弹出窗口,它应该像这样工作: 3 秒后,它会显示关闭按钮,但当您等待 3 秒时,将会有倒计时。 我的问题是没有显示文字
var n = 3;
function popup() {
set.setTimeout(function() {
getElementById('bro').style.visibility = visible;
}, 3000);
while (n > 0) {
set.setTimeout(function() {
n--;
}, 1000);
n.toString()
getElementById('texto').innerHTML = n;
}
}
function bro() {
getElementById('bro').style.display = "none";
getElementById('texto').style.display = "none";
getElementsByName('block').style.display = "none";
}
#bro {
position: absolute;
left: 50px;
top: 150px;
visibility: hidden;
justify-content: center;
z-index: 3;
font-size: 20px;
}
#texto {
position: absolute;
justify-content: center;
transition: none;
background-color: inherit;
padding: inherit;
z-index: 1;
}
aside {
position: absolute;
justify-content: center;
width: 600px;
height: 500px;
background-color: blue;
border-radius: 30px;
z-index: 2;
}
<body onload="popup()">
<p id="texto" color="red">3</p>
<button id="bro" onclick="bro()">close</button>
<aside name="block"></aside>
</body>
【问题讨论】:
-
我认为你需要 document.getElementById 而不仅仅是 getElementById
-
还有一个与元素同名的全局函数会导致问题。
-
什么是
set?除非它是对window对象的引用(它本身会非常奇怪),否则您的setTimeout()调用将导致语法错误。 -
您希望超时内的 n-- 更改您在超时外调用它的文本???它不是那样工作的。对变量的引用不会更新 innerHTML ..... 同样没有意义为什么你会有一个 while 循环并运行 setTimeout。看起来您将锁定浏览器。
-
我建议您在尝试之前多看一些 js 教程,如上所述,set.setTimeout() 是什么?此外,您根本没有引用 dom, document.querySelector('#textto'); document.querySelector('#bro') document.querySelector('.block') 并且您将可见性与显示混为一谈。我会说从顶部开始
标签: javascript jquery html dom