1.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script>
function test(){
console.log("hello");
}
</script>
</head>
<body>
<input type="button" value="按钮" id="button" onclick="test()"/>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<input type="button" value="按钮" id="button" />
<script>
document.getElementById("button").onclick=function(){
console.log("hello");
}
</script>
</body>
</html>
3.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<input type="button" value="按钮" id="button" />
<script>
document.getElementById("button").addEventListener("click",function(){
console.log("hello");
})
</script>
</body>
</html>