Html--javascript Introduction

Source: Internet
Author: User
Tags button type

First, Introduction:

JavaScript is a scripting language that requires a host file, and his host file is an HTML file.

JavaScript is a web-enabled language that works on PCs, laptops, tablets, and mobile phones.

JavaScript is designed to add interactivity to HTML pages.

Many HTML developers are not programmers, but JavaScript has a very simple syntax. Almost everyone has the ability to add small JavaScript fragments to a Web page.

Tip: JavaScript and Java are two completely different languages, both conceptually and in design.

Java (invented by Sun) is a more complex programming language.

ECMA-262 is the official name of the JavaScript standard.

JavaScript was invented by Brendan Eich. It appeared in Netscape in 1995 (the browser has stopped updating) and was adopted by the ECMA (a standard association) in 1997.

Disadvantage: You cannot operate on a database.

The annotation language is the same as C #, with "//".

JavaScript usage:

1. JavaScript has three locations:

1), head inside

JavaScript functions in

In this example, we put a JavaScript function in the

The function is called when the button is clicked:

Instance
<! DOCTYPE html>function MyFunction () {document.getElementById ("Demo"). innerhtml="My First JavaScript Function";}</script>"Demo">a Paragraph</p><button type="Button"onclick="myFunction ()">try it</button></body>

2), Body inside

JavaScript functions in <body>

In this example, we put a JavaScript function in the <body> section of the HTML page.

The function is called when the button is clicked:

Instance
 <! DOCTYPE html> "  demo   " >a paragraph</p> <button type=  " Onclick="  myfunction ()   " >try it</button><script>function myFunction () { document.getElementById (  demo  ). Innerhtml= my first JavaScript Function   " ;}  </script></body>

Tip : We put JavaScript at the bottom of the page code to ensure that the script is executed after the <p> element is created.

3),

For the sake of insurance, preferably written after </body>

2. Keyword: script

Format: <script type= "Text/javascript" > Code to write </script>

The script in the HTML must be between the <script> and </script> tags.

The script can be placed in the <body> and

<script> tags

To insert JavaScript into an HTML page, use the <script> tab.

<script> and </script> will tell JavaScript where to start and end.

The lines of code between <script> and </script> contain JavaScript:

<script>alert ("My first JavaScript"); </script>

No need to understand the above code. Just understand that the browser interprets and executes JavaScript between <script> and </script>.

Older instances may use the type= "Text/javascript" in the <script> tag. It is not necessary to do so now. JavaScript is the default scripting language in all modern browsers and HTML5.

3. Reference external file (foreign): Add an outer, must be written in the head.

You can also save the script to an external file. External files typically contain code that is used by multiple Web pages.

Create a new JS file--and then reference it in the source file:

Format: <script type= "Text/javascript" src= "new folder name. js" >

The file name extension for external JavaScript files is. js.

It is possible to refer to a script file in

Tip: External scripts cannot contain <script> tags.

4. Three common dialog boxes:

1), alert ("")--warning dialog box, the function is to pop up a dialog box, the alert () function is not commonly used in JavaScript, but it is very convenient for code testing.

2), confirm ("")--Determine the dialog box, the function is to pop up a selection of the OK dialog box, click OK, return true; Click Cancel, return false; You can use a variable to receive it.

3), Prompt ("")--Pop up a dialog box to enter the content, display the text to be prompted;

For example:

"content-type" content="text/html; Charset=utf-8" /><title> Untitled Document </title>"text/javascript">      alert (" Warning: An error has occurred! ");     </script>
"content-type" content="text/html; Charset=utf-8" /><title> Untitled Document </title>"text/javascript">     confirm (" OK to modify?")  Are you sure you want to quit? ");     </script>
<! DOCTYPE HTML Public"-//W3C//DTD XHTML 1.0 transitional//en" "HTTP://WWW.W3.ORG/TR/XHTML1/DTD/XHTML1-TRANSITIONAL.DTD">"http://www.w3.org/1999/xhtml">"Content-type"Content="text/html; Charset=utf-8"/><title> Untitled Document </title>"Text/javascript">Prompt ("Please enter a number","Note that the number is entered! "); </script>

Html--javascript Introduction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.