1. JavaScript: Write HTML output
This is a paragraph
");2. JavaScript: react to events
3. JavaScript: Change HTML content
4. JavaScript: Change HTML images
5. Change HTML style
6. JavaScript is case-sensitive.
JavaScript is case-sensitive.
When writing JavaScript statements, be sure to turn off the case switch.
The functions getElementById and getElementbyID are different.
Likewise, the variable myVariable is different from MyVariable.
7. Tip: A good programming habit is to declare the required variables at the beginning of the code.
8. Value = undefined
In computer programs, variables with no value are often declared. The value of a variable declared without a value is actually undefined. After executing the following statement, the value of the variable carname will be undefined:
var carname;
9. Create JavaScript objects
This example creates an object named "person" and adds four properties to it:
10. JavaScript form verification
Required (or required) items
The following function is used to check whether the user has filled in the required (or required) items in the form. If required or the required field is empty, a warning box will pop up and the return value of the function is false, otherwise the return value of the function is true (meaning there is no problem with the data):
<html> <head> <script type="text/javascript"> function validate_required(field,alerttxt) { with (field) { if (value==null||value=="") {alert(alerttxt);return false} else {return true} } } function validate_form(thisform) { with (thisform) { if (validate_required(email,"Email must be filled out!")==false) {email.focus();return false} } } </script> </head> <body> <form action="submitpage.htm" onsubmit="return validate_form(this)" method="post"> Email: <input type="text" name="email" size="30"> <input type="submit" value="Submit"> </form> </body> </html>
The above is the entire content of this article, I hope you all like it