2016/2/21 JavaScript Introduction

Source: Internet
Author: User
Tags array definition visibility

What is 1,javascript?
is a scripting language that requires a host file, and its host file is an HTML file.
2, what does it have to do with Java?
There is no direct relationship, Java is Sun (acquired by Oracle),
Netspace (Netscape, US online acquisition), JScript is Microsoft's,
Similar to Java 90%, but some of the features are only available on IE.
3, its usage:
There are three blocks in the HTML position:
①head inside ②body inside ③For insurance purposes, it is generally written after <script.language= "JavaScript" > code must be placed in this area </script>
4, three common dialog boxes:
The ①alert ("") warning dialog box is the function that pops up a warning dialog box.
②confirm ("") determines the dialog box, the function is to pop up a selection of the OK dialog box, after clicking OK, it returns ture, click Cancel to return False, you can use the variable to receive.
③prompt ("Hint text to display"), which pops up a dialog box that allows you to enter content.

Two, JavaScript syntax
1, basic data type
string, Decimal, Integer, DateTime, Boolean, and so on.
2, variable:
are general-purpose Var, you can store other types of values casually, can be used directly, not defined. But customary definition.
Define variable: var A;//all variable definitions are defined with Var, var is a generic mutable type.
var s= "3.14"; var n=parsefloat (s); s+=5;
var d=parseint (s);
3, array:
Array definition: new array ();//Its length is dynamically changing, You can put any type of element inside.
Assignment of array elements: a[0]=123; a[1]= "Hello";//The index of the element starts with 0. The value of the
array: a[i];
The properties of the array: a.length;//zz the number and length of array elements.
Method: A.sort ();//array sorting, sorted by the first character of each element. A.reverse ();//Flip an array.
4, Function:
Four elements of a function: name, input, return value, machining. Functions defined by the
Function: function Add (parameter) {The}//function is named Add, the input is the form of a parameter, the return value can be a var type, or a return value can be returned. 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 a departure event")/>
3, define the variable 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";
Doucument.write (Student.name);
(indicates print Zhang San)
<script src= "" ></script>

1, type conversion:
It is divided into automatic conversion and casting, which is generally used for casting.
Other types are converted to integers: parseint ();
Other types convert to decimals: parsefloat ();
Determine if it is a valid number type: IsNaN ();
is a number then returns false, not a number to return ture.

Example:

1 <!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd ">2 <HTMLxmlns= "http://www.w3.org/1999/xhtml">3 <Head>4 <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" />5 <title>Untitled Document</title>6 </Head>7 8 <Body>9 <PID= "P">The weather is nice today</P><inputname=""type= "button"value= "Click to make text disappear"onclick= "visible ()" /><inputname=""type= "button"value= "Click to make text display"onclick= "Visible1 ()" />Ten </Body> One </HTML> A <Scripttype= "Text/javascript"> - varAA=Prompt ("Please enter a positive integer","For example 5"); - if(AA!=NULL &&AA!="") the { -     varb=IsNaN (AA); - alert (b) - } + functionvisible () - { +     vara=document.getElementById ("P"); A a.style.visibility="Hidden"; at } - functionVisible1 () - { -     vara=document.getElementById ("P"); - a.style.visibility="Visible"; - } in </Script>


Prompt ("Please enter a number", "can only be a number");

Need to put prompt in isNaN method

2. Operators:

Mathematical operators: +-*/%++--;
Relational operations: = =! = >= <= ><;
Logical operator;&& | | !;
Other operators: + = = *=/=%=? :

3, Statement:
It is generally divided into sequential, branching, and cyclic statements.
(1) Branch statement if:
if (judging condition)
{

Statements that meet the criteria to be executed

}
Else
{
Statements executed when a condition is not met

}
(2) Loop for statement:
for (initial condition; cyclic condition; state change)
{
Loop body
}
(iii) Type of problem: exhaustive, iterative.
(d) Two keywords: break and continue.
(v) If you want to output the value of a parameter: the value of the output is "+a+" and "+b"
<script>function Visiblel ()
{

$ ("P"). Hide (); Have a problem

$ (function () {  /*code here*/  })  this notation is common in jquery, and $ is actually a reference to jquery, function and jquery (function () {  /*code here*/}) a meaning.
Only a reference to the jquery $ symbol really works

};</script>Value= "Dot here let the text disappear"/><p> I will disappear </p>
$ ("ID1") equivalent to document.getElementById ("Id1") (file. Get element through ID)

The basic concept of 1,dom
The DOM is the Document Object model, which is a tree model; a document is a label document; An object is a document; A model refers to something that is abstract.
2,windows Object Manipulation
One, properties and methods:
Property (value or Sub-object):
Opener: Opens the source window of the current window, or opener is null if the current window is open for the first time the browser is started.

Dialogargument: The return value of the dialog box.

Sub-object: History Location Status MenuBar toolbar, etc.

Method (function): event (the degree of pre-set, triggered).

window.open ("Part I", "Part II", "Part Three", "Part IV")
Characteristic parameters of window.open:

Name like grouping


jquery animation effects
onMouseOver put on the time-varying light click on the roll to the middle
CSS Styles

Round Shield

1 prompt to add condition if &&
0 F
3wschool Self-examination

2016/2/21 JavaScript Introduction

Related Article

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.