Javascript basics and javascript beginners are recommended in javascript beginners.
Some time ago, when I read the javascript advanced tutorial, I found many basic javascript concepts that I don't understand.
I searched the internet and saw that 《Basic javascript tutorial (version 8th)I bought one.
Author: (US) Tom Negrino Dori Smith Translator: Chen Jian Liu Jing book series name: Turing Program Design Series Press: People's post and telecommunications Press
After reading it, I benefited a lot and decided to recommend this book to beginners of javascript.
Readers of this book must have a certain HTML base, because javascript is basically a Dom operation, so it seems convenient to have a certain HTML base. The biggest benefit of this book is that every line of code is explained in detail. It can be said that it is to take the reader to get started.
For example:
Chapter 2, Chapter 2.10, using multi-level conditions
Script 2-14 This section of HTML creates a multi-level condition page
<!DOCTYPE html>
Script 2-15 This Condition Statement allows you to check multiple possibilities
window.onload = initAll;function initAll() {document.getElementById("Lincoln").onclick = saySomething;document.getElementById("Kennedy").onclick = saySomething;document.getElementById("Nixon").onclick = saySomething;}function saySomething() {switch(this.id) {case "Lincoln":alert("Four score and seven years ago...");break;case "Kennedy":alert("Ask not what your country can do for you...");break;case "Nixon":alert("I am not a crook!");break;default:}}
Use the switch/case statement
1. window. load = initAll;
Call the initAll () function when loading the page.
2. function initAll (){
Document. getElementById ("Lincoln"). onclick = saySomething;
Document. getElementById ("Kennedy"). onclick = saySomething;
Document. getElementById ("Nixon"). onclick = saySomething;
}
In this function, we set the onclick handler for each button on the page. Because the id and value attributes are set in HTML, you can use getElementById () to set the event handler. If the value attribute exists, you can use getElementById () to call it, so you do not need to set the id attribute.
3. function saySomething (){
This line starts the saySomething () function.
4. switch (this. id ){
The id of this object is used as the switch () parameter. This value determines which of the following case statements is executed.
5. case 'lincoln ":
Alert ("Four score and seven years ago ...");
Break;
If the id of this object is Lincoln, the actual warning message is displayed. If you click Lincoln, the code is displayed. However, the operation we need has been executed here, so we want to leave the switch statement. Therefore, we need to use the break statement. If there is no break, all the following code will be executed. Although it is necessary to continue executing the following branches in some cases, we should not do this in this example.
6. case "Kennedy ":
Alert ("Ask not what your country can do for you ...");
Break;
If you click Kennedy, the case block is displayed.
7. case "Nixon ":
Alert ("I am not a crook! ");
Break;
Finally, if you click Nixon, another warning dialog box is displayed. Then exit the switch statement.
8. default:
If the user input does not match the preceding conditions, the code is executed here. That is to say, if the switch value does not match any case value, it will enter the default part. Part of the default block is optional, but it is a good programming habit to include the default block. In this script, there is no need to execute the code here, because we should not be able to enter the default part.
9 .}
The right curly braces end the switch statement.
The above is a small example in the book. The examples in the book are all like this. They are basically explained in a line and line. It is suitable for beginners to learn javascript.
This book focuses on understanding and application of javascript. After reading this book, the basic javascript statements should no longer be a problem.
If you are interested, you can buy a book.