JavaScript Basics FAQ _ Basics

Source: Internet
Author: User
Tags current time html page local time

        today saw a very good JavaScript FAQ on the web, trying to translate some content and share it with friends for fear that they would not be able to read it all the time.
        FAQ Original Address: http://www.javascripter.net/faq/index.htm

        First, frequently asked questions

1, about this FAQ (about this FAQ)

Q: Why use this FAQ?

a: The purpose of this FAQ is to help you develop strong client-side scripts that can run on Netscape Navigator as well as on Microsoft Internet Explorer and under a variety of operating systems. This FAQ collects content that is different from the following:

Here the answer is based on platform-independent coding, not for a particular browser or platform.
Most of the answers here contain interactive code that you can run and get results without leaving the page you're browsing: This needs to be run on the original text and clicked on the title to get into the original text.

Here you can find the solution to the problem, not just confirm the problem exists. For example, other resources might say: Sorry, JavaScript cannot read files from the server. And this FAQ will give you a solution: This is a Java applet that can help JavaScript read files from the server.

2. What's JavaScript (What is JavaScript)

Q: What is JavaScript?

A: JavaScript is a scripting language designed to add interactivity to an HTML page. In 1995, it was first implemented by the Netscape community in 2 Beta on Netscape Navigator. JavaScript is different from the Java language (developed by Sun Microsystems). However, the two are well interoperable.

A JavaScript language or script that is usually embedded directly in the middle of an HTML file. When the user's browser opens the HTML file, the script executes. (There's actually a service-side JavaScript, but it's beyond the scope of this FAQ.) )
JavaScript is a kind of explanatory language. This means that the script does not compile ahead of time, that is, the script does not convert the system-related machine code. The user's browser interprets the script, that is, parse and execute immediately. JavaScript is supported by the following browsers:

Netscape Navigator (starting from 2.0)

Microsoft Internet Explorer (starting from 3.0)

Some other browsers/products, their manufacturer licensed or implemented JavaScript interpreter (e.g. Opera,firefox)

As a result, most Internet users currently have browsers that support JavaScript. This is why JavaScript is one of the most popular tools for adding interactivity to a Web page.

3. JavaScript features (JavaScript Features)

Q: What can JavaScript programs do?
A: The following list shows some of the typical tasks in which JavaScript functions prominently:

Give users more control over the browser

Detects user's browser, operating system, screen size, etc.

Perform a simple calculation on the client

Validating the user's input

Processing date and time

Do not access the Web server to generate HTML pages during run

Below you will find a few simple examples to illustrate each task.

I. Give users more control over the browser

Example : Here you can modify the background color of the page, as well as the text on the browser status bar.

Choose the background colorLight YellowPinkLight BlueLight GreenWhiteGray Text on the status barNo textWelcome to javascript!JavaScript is isn't Java. It ' s better!I Love javascript!

Here is a Back button implemented by JavaScript. Click on it and it will go back to the page you visited earlier.

II. Detect the user's browser and operating system. . If needed, this ability detects user's browser and operating system information, allowing you to perform platform-related operations.

example , users of different browsers receive different greetings:

Iii. perform a simple calculation on the client.

Example : This is a JavaScript calculator, and when you enter an arithmetic expression, JavaScript calculates its value.

Iv. Verify the number of user input.

example : In the above calculator, if you enter letters instead of numbers, you get a warning: invaid input characters!

Note that JavaScript assists the browser in performing input checksums without wasting the time the user accesses the Web server. If the user makes a mistake while typing, he will be prompted immediately. On the other hand, if the input information can only be inspected on the server, then the user will have to wait for the server to respond.

v. Processing date and time.

Example 1: This is a JavaScript clock.

local time:

Example 2: This script will say "nice morning, isn ' t it?" according to the current time. or "Good afternoon!." Or "Wow, you are isn't sleep yet!?". It will also tell you the date of today.

VI. Generate HTML pages in run.

Example : The directory on the left (translator Note: In the original text, the left side is a directory) is dynamically expanded. To view all the subkeys of an item, click the white arrow corresponding to it. When hiding, click the arrow.

Each time you click on these arrows, the browser produces and displays a new HTML page in the left frame. It is because of JavaScript that this can be done on the client side, so you don't have to wait for information to go back and forth between the browser and the Web server.

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.