html-dom
html-dom copied to clipboard
delete does not take effect when remove the event handler
in "Attach or detach an event handler”
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Static Template</title>
<style></style>
</head>
<body>
<button id="btn1">onclick</button>
</body>
<script>
function fn1() {
alert(1);
}
const btn1 = document.getElementById("btn1");
btn1.onclick = fn1;
console.log(btn1);
let res = delete btn1.onclick;
console.log(res);
console.log(btn1.onclick);
</script>
</html>