JavaScript에서 버튼 클릭 시 함수를 호출하려면 onclick을 사용하십시오. JavaScript에서 onclick 함수를 호출하기 위해 다음 코드를 실행해 보십시오. -
예시
<html>
<head>
<script>
function sayHello() {
document.write ("Hello there!");
}
</script>
</head>
<body>
<p>Click the following button to call the function</p>
<form>
<input type = "button" onclick = "sayHello()" value = "Say Hello">
</form>
<p>Use different text in write method and then try...</p>
</body>
</html>