" 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?

Is there a click event in JavaScript?

WBOY
WBOYOriginal
2022-01-19 16:14:171443browse

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};".

Is there a click event in 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:

Is there a click event in JavaScript?

##After clicking the button:

Is there a click event in JavaScript?

Related recommendations:

javascript learning tutorial

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn