방법 1 :
코드 예 :
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script>
function test(){
console.log("hello world!");
}
</script>
</head>
<body>
<input type="button" value="按钮" onclick="test()" />
</body>
</html>
방법 2 :
코드 예 :
<!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 world!");
}
</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 world!");
})
</script>
</body>
</html>