with "Visual QuickStart Guide javascript and Ajax for the Web, Sixth Edition"
By Tom Negrino, Dori Smith
target browsers:
Internet Explorer 6 or later; Firefox 1.0 or later; Netscape 7 or later; all versions of Safari; and Opera 7 or later.
Chapter 1. Getting Acquainted with javascript
What javascript Is
Despite the name, javascript and Java have almost nothing to do with one another.
With Java, a descendant of the C and C++ programming languages, programmers can create entire applications and control consumer electronic devices.
Microsoft dropped Sun's Java from Windows altogether, after creating its own Java-like language, C#.
If javascript isn't related to Java, then why do they have such similar names? It's another example of one of the computer industry's most annoying traits: the triumph of marketing over substance.
and ever since then, writers like us have made good money explaining that javascript and Java are very different things.
This Microsoft version of javascript is called JScript.
What javascript Can Do
A rollover is an image that changes when you move the mouse pointer over it.
javascript has some limitations built-in, mostly for security reasons:
1.javascript does not allow the reading or writing of files on client machines. The only exception is that javascript can write to the browser's cookie file.
2.javascript does not allow the writing of files on server machines.
3.javascript cannot close a window that it hasn't opened.
4.javascript cannot read information from an opened Web page that came from another server.
What Is Ajax?
Ajax is shorthand for Asynchronous javascript and XML.
In the larger scheme of things, what's generally referred to as Ajax is the combination of these technologies:
XHTML
CSS (Cascading Style Sheets)
The DOM (Document Object Model) accessed using javascript
XML, the format of the data being transferred between the server and the client
XMLHttpRequest to retrieve data from the server
javascript is an object-oriented language
Objects
Properties, Objects have properties.
Methods, The things that objects can do are called methods.
dot syntax
document.images.name
forms.elements.radio.click()
The representation of the objects within the document is called the Document Object Model (DOM).
Each of the objects on the tree is also called a node of the tree. If the node contains an HTML tag, it's referred to as an element node. Otherwise, it's referred to as a text node.
Events are actions that the user performs while visiting your page. javascript deals with events using commands called event handlers.
The 12 most common javascript event handlers :
onabort
onblur
onchange
onclick
onerror
onfocus
onload
onmouseover
onmouseout
onselect
onsubmit
onunload
value Types:
Number
String
Boolean
Null
Object
Function value returned by a function
Variable names cannot contain spaces or other punctuation, or start with a digit. They also can't be one of the javascript reserved words. javascript is case sensitive.
Operators:
x + y (Numeric)
x + y (String)
x – y
x * y
x / y
x % y Modulus of x and y (i.e., the remainder when x is divided by y)
x++, ++ x
(if x is 5, y=x++ results in y set to 5 and x set to 6, while y=++x results in both x and y set to 6. The operator – (minus sign) works similarly.)
x–, –x
-x
Assignments:
x = y
x += y
Same as x = x + y
x -= y
x *= y
x /= y
x %= y
Comparisons:
x == y
x != y
x > y
If you are comparing strings, be aware that "a" is greater than "A" and that "abracadabra" is less than "be".
x > = y
x < y
x <= y
x && y
x || y
!x
Writing javascript-Friendly HTML
Structure, presentation, and behavior
When split up this way, your sites will contain three types of text files:
XHTML: content and structure
CSS: appearance and presentation
javascript: behavior
CSS:
A <div> is a block-level element, that is, there's a physical break between it and the elements above and below it. A <span> isn't block-level; instead, it's inline, so you can apply it to, for instance, a single phrase within a sentence.
A class identifies an element that you may want to use more than once. An id identifies an element that is unique to that document.
轉載請註明: 轉自船長日誌, 本文鏈接地址: http://www.cslog.cn/Content/learning_javascript_1/zh-hant/