when using a timer, there are two buttons, one is to set the timer and the other is to clear the timer, but clearTimeout does not work and the output is still on the console. Why and what went wrong? The
code is as follows:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script>
var settime=null;
function insert(){
settime=window.setTimeout(showalert,3000);
}
function showalert(){
console.log("");
}
function clear(){
window.clearTimeout(settime);
}
</script>
</head>
<body>
<div id="a">
<h3>setTimeout</h3>
<button onclick="insert()"></button>
<button onclick="clear()"></button>
</div>
</body>
</html>