I keep getting a "Undefined function" JavaScript error in my error console. Any idea why?
<div id="counter" style="width: 40px;"></div>
<script type="text/javascript">
var seconds = 60
document.getElementById('counter').innerHTML = seconds
function countDown() {
if(seconds <= -1) {
seconds += 1
} else {
seconds -= 1
document.getElementById('counter').innerHTML = seconds
setTimeout("countDown()", 1000)
}
}
countDown();
</script>
您可能要考虑添加一些分号。
The undefined function may be document.getElementById if you execute this piece of code before the document is loaded. But I could be wrong.
对我而言,它的值为-1,即您在“ if”语句中的值。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.