var ele=Boolean(document.getElementById("seconds").innerHTML>=30)
while(ele==false)
if(ele){
我想经常检查这个并在它成立后运行它。我怎样才能做到这一点?我想只运行while循环,然后在控制台中运行if循环。
答案 0 :(得分:2)
在控制台中运行while
循环的测试迅速崩溃了我的浏览器。不是个好主意。请尝试在页面中使用setInterval
。
<!doctype html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<div id="seconds">30</div>
<script>
var myTest;
myTest = setInterval(checkElement, 100);
// elem is set outside the function so the function runs quicker, but in reality, this won't make a significant difference in this example
var elem = document.getElementById("seconds");
function checkElement(){
if(parseInt(elem.textContent)>30){
console.log(Math.random());
clearInterval(myTest);
}
}
</script>
</body>
</html>