html-Lesson Plan-javascript Introduction

Source: Internet
Author: User

First,JavaScript Introduction

What's a 1.JavaScript thing?

It is a scripting language and requires a host file whose host file is an HTML file.

2. What does it have to do with Java ?

There is no direct connection,Java is the Sun Company (has been acquired by Oracle ),JavaScript is a Netspace (Netscape, which has been acquired by AOL), JScript It's Microsoft's, 90% like JavaScript , some features can only be IE used on.

3. its usage:

There are three blocks in the HTML position:

(1) inside head

(2)body inside

(3) after

For insurance purposes, it is generally written after .

<script language= "JavaScript" > code must be placed in this area </script>

4. three common dialog boxes:

  alert ("") A warning dialog box that pops up a warning dialog box.

  confirm ("") determines the dialog box, the function is to pop up a selection of OK dialog box, after clicking OK, it returns ture , click Cancel to return false , you can use variables to receive them.

  prompt (" hint text to display "), the function is to pop up a dialog box that allows you to enter content.

Second,JavaScript Syntax

1. Basic data type:

String, Decimal, Integer, DateTime, Boolean, and so on.

2. variables:

are generic type var, can store other types of values, can be used directly, not defined. But it's customary to define.

Defining variables: var A; all variable definitions are defined by var andvar is a generic mutable type.

var s = "3.14"; var n = parsefloat (s);; s + = 5;
var d = parseint (s);

3. Arrays:

Definition of the array:new Array (); Its length is dynamically variable and can be placed in any type of element.

Assignment of array elements:a[0]=123; a[1]= "Hello"; The index in the element starts at 0 .

The value of the array:a[i];

Array properties:a.length; the number and length of array elements.

Methods:A.sort ();// array Sorting, sorted by the first character of each element.   a.reverse (); flips the array.

4. functions:

Four elements of a function: name, input, return value, processing.

Define functions: FunctionAdd ( formal parameter ) { function body }// function named add, input as Parameter form , the return value can be either a var type or a return value.

The function must be called to execute. Call to function:add(argument).

* can be read on the head (first read the head)

The page is automatically refreshed when the form is submitted, preferably turned off

Writing:

1. Output

<script>

document.write ("Hello World");

</script>

2. Button Application

<input name= "alert" value= "alert" type= "button" onclick= ' Alert (" This is the trigger event ") '/>

3. Define variables and output

   var Bianliang;

Bianliang= "123";

document.write (Bianliang);

4. Changing the attributes of an element

<p id= "Hello" >hello</p>

<script>

function Hello ()

{

X=document.getelementbyid ("Hello")

X.style.color = "#ff0000";

}

</script>

<input type= "button" value= " Click to change color " onclick= "Hello ()"/>

<!-- Click From Black to Red --

5, item index, indicating The nth occurrence of the element, with getelementsbyname simultaneous use

Define a set of variables

var student =

{

Name: " Zhang San ",

Sex: " male "

};

Student.name= " Zhang San ";

document.write (Student.name);

(* print " Zhang San ")

External call JS

<script src= "" ></script>

html-Lesson Plan-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.