onclick event
Examples
Javascript code is executed when the button is clicked ::
<button onclick="myFunction()">Click me</button>
try it"
Definition and Usage
onclick event occurs when the element is clicked.
grammar
In HTML:
<element
onclick="SomeJavaScriptCode">
In JavaScript:
object .onclick=function(){SomeJavaScriptCode};
参数 | 描述 |
---|---|
SomeJavaScriptCode | 必需。规定该事件发生时执行的 JavaScript。 |
Browser Support
All major browsers support onclick event
It supports HTML tags onclick event:
onclick attribute can be used with all HTML elements except: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style> , and <title>.
Event objects