1. JavaScript: Write HTML output
The
code is as follows:
document.write ("<h1>this is a heading</h1>");
document.write ("<p>this is a paragraph</p>");
2. JavaScript: Responding to events
The
code is as follows:
<button type= "button" onclick= "alert (' welcome! ')" > Click here </button>
3. JavaScript: Change HTML content
The
code is as follows:
X=document.getelementbyid ("demo")//Find element
x.innerhtml= "Hello JavaScript"; Change Content
4. JavaScript: changing HTML images
The
code is as follows:
Element=document.getelementbyid (' myimage ')
element.src= ". /i/eg_bulboff.gif ";
5. Change HTML Style
The
code is as follows:
X=document.getelementbyid ("demo")//Find element
x.style.color= "#ff0000"; Change Style
6, JavaScript is sensitive to case.
JavaScript is sensitive to capitalization.
When writing JavaScript statements, be aware of closing the case toggle key.
The function getElementById is different from the getElementById.
Similarly, variable myvariable and myvariable are also different.
7, Hint: a good programming habit is, at the beginning of the code, unified to the required variables to declare.
8, Value = undefined
In computer programs, variables that are not valued are often declared. A variable that is not declared with a value, and its value is actually undefined. After the following statements have been executed, 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:
copy code code as follows:
person=new Object ();
person.firstname= "Bill";
person.lastname= "Gates";
person.age=56;
person.eyecolor= "Blue";
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 a required or required option is blank, the warning box pops up and the function's return value is false, otherwise the function's return value is true (meaning there is no problem with the data):
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
The above mentioned is the entire content of this article, I hope you can enjoy