current position:Home>JavaScript knowledge (1) Complete registration form verification with JS

JavaScript knowledge (1) Complete registration form verification with JS

2022-09-23 06:33:04zjj_learning_path

1. Components

ECMAScript: It is the core of the entire JavaScript, including basic syntax, variables, keywords, reserved words, data types, statements.

DOM: Document Object Model, which contains the content of the entire HTML.

BOM: Browsing Object Model, containing the entire browser-related content.

2.ECMAScript syntax

(1) case sensitive

(2) Variables are weakly typed, using the var definition keyword.

(3) At the end of each line; optional.

(4) Variable declaration is not required

(5) === is equal to true without type conversion

3. Get element content

document.getElementById("id name") Note: If it is a string, double quotes must be added

4. Form submission event: onsubmit

5.javascripte output
Warning box: alert();
Write content to the specified location of the page: innerHTML(attribute)
Write content to the page: document.write("");

6. Step Analysis
Step 1: Determine the event (onsubmit) and bind a function to it
Step 2: Get the data entered by the user
Step 3: Judging the data entered by the user
Step 4: The data is legal (let the form submit)
Step 5: The data is illegal (an error message is given, and the form is not allowed to submit)

7. How to control form submission?
About the event onsubmit: generally used for form submission, then you need to give a
return value when defining the function.onsubmit = return checkForm()

Concrete implementation

1. Write

in //checkForm is not a fixed name

2. Add to the head header file, and write code in the middle (don't forget to set the id).

Check the code after clicking the submit button1. In the header file:2. Add onsubmit to the form:3. Set the id to take the username as an example

copyright notice
author[zjj_learning_path],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/266/202209230621041185.html

Random recommended