What events are there in js? Introduction to common events in js
JavaScript gives us the ability to create dynamic pages. Events are behaviors that can be detected by JavaScript. Every element in a web page can generate certain events that trigger JavaScript functions. So, what events are there in js? This article will introduce you to the commonly used events in js.
Without further ado, let’s get straight to the point.
1. Onclick event, a commonly used event in js
Click event (onclick is not a method in js, onclick is just a dom interface provided by the browser for js, so that js can operate DOM, so onclick is case-sensitive. For example, HTML code does not need to be case-sensitive).
Code example of onclick event in js:
<%@pagelanguage="java"import="java.util.*"pageEncoding="UTF-8"%> <!DOCTYPEHTMLPUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>JavaScript的一些常用方法</title> <scripttype="text/javascript"> functionmyFunction(){ alert("测试onclick点击事件"); } </script> </head> <body> <center> <buttononclick="myFunction()">点击这里</button> </center> </body> </html>
Description:
onclick is usually generated in the following basic objects:
button (button object), checkbox (check box), radio (radio button), reset buttons (reset button), submit buttons (submit button)
2. The onload event, a commonly used event in js
, can be executed by body,