This is the 8th day of my participation in the November Gwen Challenge. Check out the event details: The last Gwen Challenge 2021

preface

We’ve learned a lot about JavaScript.

In this article, we will learn about the Event in JavaScript. There are also some points to pay attention to

JavaScript Event Event

An event in JavaScript is a response event generated by a mouse/keyboard operation on an element in a browser page, or by the browser itself. For example, a form data submission event generated by clicking the submit button with the mouse, a keyboard event generated when we press a key on the keyboard, an event generated when the browser requests the page after loading, and so on.

A few typical common events

1. onclick()

The event that is triggered when you click a tag element (hyperlink/button/checkbox, etc.) on a page with the mouse is called an onclick event.

<body>
  <form>Form 1:<input value='Please enter something to submit' type="text" id="text1"/>
    <br/>The form 2:<input value='Please enter something to submit' type="text" id="text2"/>
    <br/>
    <! -- Call event function parameter event -->
    <button onclick="submitData(event)">This is a button that is clicked to generate an onclick event</button>
  </form>
  
  <script>
      // Here we define the event function argument as event
      function submitData(event) {
        let text1 = document.getElementById('text1')
        if(text1.value === ' ') {
          alert('Text1 cannot be empty')
          console.log('Text1 cannot be empty', text1.value)
        }
        let text2 = document.getElementById('text2')
        if(text2.value === ' ') {
          alert('Text2 cannot be empty')
          console.log('Text2 cannot be empty', text2.value)
        }
      }
  </script>
<body>
Copy the code

2. The onkeydown () event

The onKeyDown () event is the triggering event that occurs when we press a key on the keyboard.

3. The onload () event

The onload() event is the browser’s event: an event that occurs when the browser has finished loading the page: the onload event

reading

  1. Automatic type conversion
  2. -number – This is a function
  3. Infix operators in JavaScript
  4. Do you know what JavaScript Typeof is?

Come on

Buy Less by Know More!

Learning, recording and accumulating is a long process! Come on!