<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<button>click</button>
<script>
document.getElementsByTagName('button')[0].onclick = function() {
alert(2)
}
document.getElementsByTagName('button')[0].click()
</script>
</body>
</html>