JavaScript binds the button to the click event (onclick) method


This article illustrates how JavaScript binds click events (onclick) to buttons. Share with you for your reference. The specific analysis is as follows:

We can bind the onclick event to the button by setting the onclick property of the button

<!DOCTYPE html>
<html>
<head>
<script>
function displayDate()
{
document.getElementById("demo").innerHTML=Date();
}
</script>
</head>
<body>
<h1>My First JavaScript</h1>
<p id="demo">This is a paragraph.</p>
<button type="button" onclick="displayDate()">
Display Date</button>
</body>
</html>

PS: here is another recommended online query tool about JS event, which summarizes the commonly used event types and functions of JS:

javascript event and function description:

http://tools.ofstack.com/table/javascript\_event

I hope this article is helpful for you to design the javascript program