다음이 우리의 버튼이라고 가정해 봅시다 -
<button onclick="displayingMessageOnButtonClick()">Press Me</button>
위 버튼을 클릭하면 함수를 호출해야 합니다.
예시
다음은 코드입니다 -
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<body>
<p id="showTheTextMessage"></p>
<button onclick="displayingMessageOnButtonClick()">Press Me</button>
</body>
<script>
function displayingMessageOnButtonClick() {
const showMessage = document.getElementById('showTheTextMessage');
showMessage.innerHTML = 'Welcome to Javascript Program...';
showMessage.style.display = 'block';
}
</script>
</html> 위의 프로그램을 실행하려면 anyName.html(index.html)이라는 파일명으로 저장합니다. 파일을 마우스 오른쪽 버튼으로 클릭하고 VS Code 편집기에서 "실시간 서버로 열기" 옵션을 선택하십시오 -
출력
출력은 다음과 같습니다 -

이제 버튼을 누릅니다. 다음은 출력입니다 -
