JavaScript language basics 2: javascript language basics
Let's take a look at the following code:
<HTML><HEAD><TITLE>Hello World</TITLE></HEAD><BODY><SCRIPT Language="JavaScript" TYPE="text/javascript">document.write("Hello World")</SCRIPT></BODY></HTML>
Save as the suffix of .html and check the effect in the browser:
When adding JavaScript code to a webpage, the following tags must be used: <script> </script>
It starts with <script> and ends with </script>. The code in this area is called a script block.
From the code above, we can see that the script block is placed between <BODY> and </BODY>, and the <script> position is random. It can be placed in the header of the HTML page, between <HEAD> </HEAD> or between <BODY> </BODY>,
<SCRIPT Language = "JavaScript" TYPE = "text/javascript">
<Script> the tag has some attributes, the most important of which is the type attribute. When using a script, we need to tell the browser which script language we are currently using, so that the browser can handle the problem correctly. Therefore, we set the type to text/javascript.
The type attribute can also be omitted on a page, because the current browser uses JavaScript as the default scripting language. However, W3C, which develops the HTML standard, lists the type attribute as a mandatory specification,
<span style="font-size:18px;">document.write("Hello World")</span>
The document object represents a webpage, that is, "Hello World" is displayed on the webpage. The document object has many attributes, such as bgColor.
<HTML><HEAD><TITLE>Hello World</TITLE></HEAD><BODY BGCOLOR="WHITE"><SCRIPT Language="JavaScript" TYPE="text/javascript">document.bgColor="RED"</SCRIPT></BODY></HTML>
Display Effect:
BgColor: Set the page to red
Reprinted please indicate the source: http://blog.csdn.net/hai_qing_xu_kong/article/details/40707161 sentiment control _Click Open Link
How to Learn JavaScript
1. It is best to learn C language well. C language is the foundation of the basics, and then it is easy to understand JavaScript.
2. There are a lot of JavaScript tutorials on the Internet.
Javascript Language
The answer is correct.
I would like to add:
It looks like this: <! -- Omitted in the middle // -->
As for why, let me say this.
<! -- This is an HTML comment -->
// This is a javascript annotation.
The effect of these two operations is that some browsers previously did not support JavaScript. Therefore, when you encounter a browser that does not support JavaScript, the JavaScript code will be treated as "HTML comments" and there will be no error in the script. If the browser supports JavaScript. Then // takes effect. In this format: // -->, where --> is commented out. So the JavaScript function is used!
In addition, JavaScript has another annotation method.
/*
Multi-line comment example
/*
Nested comment
*/
*/
// Comment the first line
// Comment the second line
Reference: tieba.baidu.com/f? Kw = javascript