" or "object.onclick=function(){JavaScript to be executed};"."/> " or "object.onclick=function(){JavaScript to be executed};".">
Home > Article > Web Front-end > Is there a click event in JavaScript?
There is a click event in JavaScript; you can use onclick to bind the click event. The syntax is "
" or "object.onclick=function(){To Executed JavaScript};".
The operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.
Is there a click event in JavaScript
HTML events can be browser behaviors or user behaviors.
The following are examples of HTML events:
HTML page finishes loading HTML input field changes HTML button is clicked
Usually, when an event occurs, you can do something .
JavaScript can execute some code when the event is triggered.
The onclick event occurs when an element is clicked.
Syntax
In HTML:
<element onclick="SomeJavaScriptCode">
In JavaScript:
object.onclick=function(){SomeJavaScriptCode};
Parameter Description
SomeJavaScriptCode Required. Specifies the JavaScript to be executed when this event occurs.
The example is as follows:
<html> <head> <meta charset="utf-8"> <title>123</title> <script> function myFunction(){ document.getElementById("demo").innerHTML="Hello World"; } </script> </head> <body> <p>单击按钮触发函数。</p> <button onclick="myFunction()">点我</button> <p id="demo"></p> </body> </html>
Output result:
Related recommendations:
The above is the detailed content of Is there a click event in JavaScript?. For more information, please follow other related articles on the PHP Chinese website!