JavaScript creates a simple script

Source: Internet
Author: User
Tags arithmetic operators

1. Add JavaScript to the Web page

The first approach: write JavaScript code directly into an HTML document

<script></script>

The second approach: writing JavaScript code to a separate file

<script src= "File path" ></script>

For example:

<script src= ". /mycode.js "></script>

<script src= "Http://www.xxx.com/.../mycode.js" ></script>

2. JavaScript statements

JavaScript internal statements end with each statement ";"

To improve the readability of the code, in general, write only one statement per line

JavaScript comment statements are commonly used in two ways:

Single-line Comment

/* is commented

Lost content */

3. Variables

There are no strict rules for the naming of variables but we generally use only letters, numbers, dollar sign $ and underscores, and the style is usually camel (capitalized)

Definition: We use the keyword var to declare a variable

var Netprice;

Netprice = 8.99;

can be written

var netprice = 8.99;

If you want to assign a string to a variable, you need to quote the string in double or single quotes.

var stringname = "Xiangcunjiaoshihujin";

4. Operator

(1) Arithmetic operators

Plus +

Reduction

By

Remove

Residual%

Self-increment + +

Self-reduction--

(2) Operator precedence

Generally according to the operator priority level to

(3) + addition operation on both sides of the left is a string so the addition operation represents the connection operation

  

var name = "Xiaohu"; var =+ age);

Will eventually get results displayed on the screen xiaohu22

5. Mouse events

Onclicks event handler (mouse click Trigger)

<input type= "button" onclick= "alert (' is ok! ')"  Value= "click Me"/>

When the mouse click on this button will pop up is ok!

OnMouseOver (mouse entry Trigger)

onmouseout (mouse off trigger)

JavaScript creates a simple script

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.