Самоучитель. Javascript
-
Upload
aaron-mercado -
Category
Documents
-
view
277 -
download
11
Transcript of Самоучитель. Javascript
-
JavaScript
-
2- ,
:
JavaScript
-
-
()
-
()JavaScript
2-
-
--
2005
-
32.988.02-0187 004.738.5(075)83
.
83 JavaScript, 2- . .: , 2005. 395 .: .ISBN 5-469-00804-5
JavaScript. , . -,
, Windows Scripting Host. JavaScript HTML. , , - .
.
32.988.02-0187 004.738.5(075)
.
.
, , , .
, ,
, .
ISBN 5-469-00804-5 , 2005
-
13
1. JavaScript 18
2.
3. 169
4. 180
5. Windows 277
1. HTML 297
2. HTML 362
385
-
11 12
13
1. JavaScript 181.1. 181.2. 22
1.2.1. alert 221.2.2. confirm 231.2.3. prompt 24
1.3. 251.4. 29
1.4.1. 301.4.2. 301.4.3. 31
1.5. 321.5.1. 321.5.2. 331.5.3. 351.5.4. 351.5.5. 371.5.6. 381.5.7. 421.5.8. 46
1.6. 481.6.1. 481.6.2. 501.6.3. 55
1.7. 551.7.1. String () 571.7.2. Array () 661.7.3. Number () 741.7.4. Math () 791.7.5. Date () 85
-
1.7.6. Boolean () 911.7.7. Function () 911.7.8. Object 95
1.8. 961.8.1. 971.8.2. 981.8.3. 991.8.4. 99
1.9. 1031.9.1. 1031.9.2. 1041.9.3. 105
1.10. 1061.11. 108
2. 1102.1. 2.2. HTML 113
2.2.1. HTML 2.2.2. HTML 116
2.3. , 1172.3.1. 1172.3.2. 1202.3.3. , 124
2.4. 1312.4.1. 1312.4.2. 1372.4.3. 139
2.5. 1402.5.1. 1412.5.2. 1442.5.3. 1502.5.4. 151
2.6. 1542.6.1. writeQ 1552.6.2. 1552.6.3. 156
2.7. 1582.8. 1612.9. Cookie 163
3. 1693.1. window 169
3.1.1. window 1693.1.2. window 1713.1.3. window 171
'
-
8
3.2. document 1723.2.1. document 1723.2.2. document 1733.2.3. document 1733.2.4. document 174
3.3. location 1753.3.1. location 1753.3.2. location 175
3.4. history 1753.4.1. history 1763.4.2. history 176
3.5. navigator 1763.5.1. navigator 1763.5.2. navigator 1763.5.3. navigator . . . * 177
3.6. event 1773.7. screen 178
3.7.1. TextRange 1783.7.2. TextRange 1783.7.3. TextRange 178
4. 1804.1. 180
4.1.1. 1804.1.2. 1824.1.3. 1834.1.4. 1844.1.5. 1854.1.6. 1884.1.7. 195
4.2. 1964.2.1. 1964.2.2. 203
4.3. 2114.3.1. 2124.3.2. 2174.3.3. , 2204.3.4. , 2214.3.5. 223
4.4. 2254.5. 2294.6. 234
4.6.1. 2344.6.2. 236
4.7. 2414.8. 244
4.8.1. 244
-
4.8.2. 2464.8.3. 2474.8.4. 2484.8.5. 2554.8.6. 2564.8.7. 2584.8.8. HTML- 2634.8.9. 2654.8.10. - 267
4.9. Flash- 2714.9.1. JavaScript ActionScript 2724.9.2. JavaScript ActionScript 275
5. Windows 277
5.1. 2785.2. 2795.3. 282
5.3.1. 2825.3.2. , 283
5.4. , 2845.4.1. 2845.4.2. , 2865.4.3. 2875.4.4. 2905.4.5. 292
5.5. 292
1. HTML 297 297 303
304 305 309 310 310 312 313 314
- 316 317 319
320 320 320
-
10
URL- 322 323
325 333
337 340 343 347
Flash- - 347 348 350 (radiobuttons) 351 353 354 355 359
HTTP-EQUIV (HTTP-) 359 NAME () 360
2. HTML 362 HTML 362
362 362 363 363 364 364 365, , 365 365 366
366 366 HTML 367 HTML 383
385
-
web- (2001) web- (2002) , JavaScript -. , -
.
, . , , HTML, - -
, . -
, , -
. , - -
HTML, , . HTML, JavaScript . ,
. -
,
.
JavaScript , 1000 . , , , , -
. , -
JavaScript, .
, . ,
, -
- .
. -
, JavaScript, . , JavaScript - C++, Java . , - , .
JavaScript, . - JavaScript ,, . ,
. - -
, ,
-
12
. ,
, JavaScript . JavaScript. . ,
www.admiral.ru/~dunaev. - . ,
. !
-
.
, , -
[email protected] ( , ). !
- http://www.piter.com - .
-
, (, ), , .
, -
, , -
, .
, , -
, .
, -
. , -
. -
; , ... . -
.
, . , -
,
, .
, ,
, ,
. -
! , -, . , . -
, ,
, ,
. , , -
, -
. ,
.
, - , . -
-
. ,
, -
. ,
, ,
, . () , -
-
14
. ,
, , . -
, . , , -
- , .
, ,
.
,
JavaScript, - . ,
(Notepad) Windows (. B.I), :W S c r i p t . e c h o ( " ! " )
5 p.oba.js- :
klScript.echo("npMBeT?");
_J ,:
. B.I.
JavaScript, . , , proba.js. , js , - , JavaScript. , - * . -
(*.*), js, proba.js (. .2). .
l -I !................
; .........
1^ |p editot.htm , htm
JavaCKpHnr.doc
. .2.
-
15
, . , -
Windows proba.js. - ! (. .). . .
Windows
. .. ,
.
:
alert("")
proba.htm. , -, -
! (. .4).
&-
. .4. Internet Explorer
-
16
, -
: .
,
, . , -
.
Windows, Windows Scripting Host, -. , JavaScript, , , -
, . -
.
, ,
() . - , -
- . . -
, . -
,
. ,
, , .
. , -
-, , -
. , -
. , JavaScript, Microsoft InternetExplorer Netscape, . , , .
, , -
. , -
.
,
. , -
.
1.5 JavaScript.
Microsoft Internet Explorer 6.0 Windows; Internet Explorer 4+ Windows, , , - Internet Explorer 5 Macintosh. Netscape Navigator 4 . , - , Internet Explorer Windows, . , -
Internet Explorer 4 Windows -, .
Internet Explorer Windows 5.5 , , , . -
JavaScript, - . - , , -
.
-
17
1 JavaScript. 2 - , -
, . ,
. -
3. - .
. ,
, 4. - ,
JavaScript -. - 5 Windows JavaScript. , . -
HTML. -
. ,
, , ,
-
. - ,
. -
. , .
-
1. JavaScript
1.1. JavaScript: - ( ). - . -,
-
: ( ) - JavaScript -. Internet Explorer 6.0. - 5.0 . - -
, Windows. - , ,
.
:
, HTML-, -. - , .htm. htm html, , -. HTML. JavaScript .
JavaScript. Enter, - . :
= 5 = + 3alert(y)
-
1.1. 19
-
. alertQ, , .
alert(y) , ( 8). alert(y), . ,
-, alert(y) :document.writeln()
( .htm) - - ,
Windows. , --
HTML > HTML. - (. 1.1). ( >). - , - > (. 1.2). , - , .
. him -
] '[>--*.-
^- TI .1/ / T T T I PSi'/IIPuri HUx\ 1 1 1 Ltxl 1\/ 1 1 ILtxx/ntHU
X = 5 = X + 3alert(y)
:I I LSI KOI,
fl iH
. 1.1. Internet Explorer
JavaScript , -, Microsoft FrontPage Macromedia Dreamweaver (. 1.3). .
-
20 1. JavaScript
- Microsoft Estpiors
. 1.2. .htm
( JavaScript/ htw") 9 . 0
:1>|j
5 htm :::
falertM
/SCRIPT>(
:By - X + 3lfalert(y)
II
$* I ||1 !^ | j~*
. 1.3. Dreamweaver 4.0 -
, .
HTML-
-
1.1. 21
.htm .html. -. :
JavaScript:
:
bBUTTON onclick="document.all.mycode.value='';document.all.myrezult.value=''">04HCTHTb
.
.
.
, Enter.
3 - Microsoft Internet Explore! Cgpac
. '
fr : 1 ^!1
JavaScript
:
= 2+3 = + 5
:
10
. .
.
, Enter.
. 1.4. JavaScript, HTML
-
22 1. JavaScript
- HTML- : JavaScript, . : - , -
. ,
. ,
JavaScript, HTML. , .
, JavaScript, - , (onclick). . 1.4 , Internet Explorer.
,
( --) > .
1.2. JavaScript -. , JavaScript -. - , -
HTML, - .
JavaScript HTML-, HTML JavaScript, - Internet Explorer, - : alertQ,promptQ confirmQ. .
1.2.1. alert
. :
1(") , -
, -
. , 1!.(" !") (. 1.5). , - : , , ( ), . , alert(), , . ,
. , -
, . , ,
alertQ, .
-
1.2. 23
Microsoft Internet Explorer
. 1.5. , !1(" !")
, 1() - .
- -
, .
1.2.2. confirm confirm - (Cancel). alert - , , -
. , true(, ); , false(, ). , -, ,
. confirm - :
confi() , -
, , -
. , conf i rm("Bbi ?") (. 1.6). , : -
, , ( ), . , -
, .
Microsoft Internet Exploiei
. 1.6. , confirm
, confirm(), . ,
. , -
, -
. , , confirmQ,
-
24 1. JavaScript
. , -
true (, ), , - false (, ). , , , -
.
1.2.3. prompt prompt , , (. 1.7). - , : (Cancel). alertQ confirm() : -, .
, ,
, false (,). , , ,
. prompt :p r o m p t ( , _ _ _ )
1
* Ornail
!|jmumu(igeiasim.tij
. . *;", :: -'.- 1
[ i, ||
. 1.7. , prompt
prompt() . , , -
undefined ( ). , , -
"". , prompt(" ,", "")(. 1.8).
. 1.8. , promptQ
, promptQ, .
confirmQ, .
-
1.3. 25
1.3. .
,
.
, ,
. (. 1.1.), , -
.
, . , -
, .
. ,
5? , - : -
. ,
, ,
. , -
, . , ,
+, , -, .
, ,
. -
. , -
, ,
. , , +, -:
, (, -).
1.1. JavaScript
(string) (number)
(, boolean)Null (object)
(function)
"" ,
".. 123-4567" , 3.14 -567 +2.5 , ,
(+ -);
+; .
true false true (, ) false (, );
,
. ,
,
-
26 1. JavaScript
() . . ,
, . -
, " '. , -345.12 , "-345.12" . - , ,
. , ,
, () . (, ) - , .
? , - , .
, , -
; , - (, , . .). -
, . ,
, .
, "", ( ), - . , (," "), .
: true false. . true (), a false - (). - , -
(, , ). , 2 < 3 -, , true (, 2 3). (boolean) , .
(Null, Object Function) -, .
JavaScript . , , -
, .
, -
. , Pascal, - , .
, 5+"", - "5". , , , , -
, . -
JavaScript , - .
-
1.3. 27
2+3 5, 2+"3" - "23", . , -
. , -
,
. -
. ,
, .
.
JavaScript - parselntQ parseFloatQ. , . , -
, .
.
parseInt(cipOKa, ) (8, 10 16). , 10, - .
parselnt("3.14") // = 3p a r s e l n t ( " - 7 . 8 7 S " ) // = -7p a r s e l n t ( " 4 3 5 " ) // = 435p a r s e l n t ( " " ) // = NaN, parselnt("15" ,8) // = 13parse!nt("0xFF",16) // = 255
, -
: .
parseFloat(cipoKa) (, ) .
p a r s e F l o a t ( " 3 . 1 4 " ) // = 3.14p a r s e F l o a t ( " - 7 . 8 7 5 " ) / / = - 7 . 8 7 5parseFloat ( " 4 3 5 " ) // = 435parseFloat ( " " ) / / = NaN, parseFloat ( " 1 7 . 5 " ) // = 435
, -
. , -
, +. , ""+3.14 "3.14". .
, , -
1$(). - . ,
true, false. - . i s N a N Q
-
28 1. JavaScript
, , . -
. true 1, false 0. , i s N a N false, , - , ,
, (true false).
isNaN(123) // false ( - )isNaN( "123") /* false ( - ,
) */i s N a N ( " 5 0 ") // true ( - )isNaN(true) // falseisNaN(false) // false1 ( " " ) // true ( - )
,
.
\ \t \f \ \
. , , , -
Internet Explorer alert(), , \ (. 1.9):
!" - - - ")
Microsoft Inletnel Exptoret
-
-
. 1.9. , alertQ, \
, . , -
, , -
? \ ( ). , " " , -
: " \" \"". ,
. -
, -
-
1.4. 29
, . Internet Explorer 1:(" \" \"") , - . 1.10.
Microsoft Internet Explorer
" "
. 1.10. !1:(" \" \"")
, ,
( ). -, : '- " "'. -
. -, -
: " ' '".
-
. , , -
: " " -
"".
.
.
-
, ,
.
, ,
, .
, ,
( , - ).
1.4. , - , -
314? , - - . .
-
, .
-
30 1. JavaScript
1.4.1. . , -
, . -
,
, -
.
: myFamily, my_adress, _x, tel412_3456. : 512group, my adress, tel:412 3456. , -
, . , -
var, if, else, const, true, false, function, super, switch . 1.11. -. , -
, -
. : my_first_adress, myFirstAdress. , () -: (character), n (number), b (boolean), (object), a (array). cAdress, nCena, aMonth.JavaScript . , - ( ) - . : variable, Variable vaRiabLe .
, -
. , -
.
1.4.2. :
:
_ =
=.
:
m y N a m e = "" var ( variable ) :
var _
,
.
:
var myNamemyName = ""
-
1.4. 31
var :
var _ =
var myName = "" var ' -
. -
, .
, -
. -
. , :
var x = ""// = ""
// = 2.5
var -
, , . -
, :
var name = "", address, x = 3.14 , ,
. , -
(), ( null) . , -
=. -
. =
: -
, .
, = : -
. ,
, = .
,
. , -
, -
. 1.5.3 -, +=, -= . .
1.4.3. ,
var , .
, ,
. -
. .
. -
. -
-
32 1. JavaScript
, . ,
var, -
: , .
.
.
, .
.
(, ). , -
. .
JavaScript . , () - HTML- -, .
1.5. .
, . -
, , -
. ,
, , ,
. , .
, , 2 3, - 5. , . -
, .
. -
=. . , -
, -
= , , ,
.
1.5.3.
1.5.1. . -
, ,
.
JavaScript : // , , -
; /*...*/ , /* */, ;
.
-
1.5. 33
. -
. -
, ( ?).
,
, , .
.
1.5.2. , , . ., JavaScript . , -
. (. 1,2).
1.2.
+
.
/%++
-
1 1
X + YX - YX* YX / YX % Y++
Y-
. -
.
. , 8%3 - 2. ++ - - , . ++ +1, X -1. ++ -- .
- ( ) , ( ) - , .
= 5 // 5 = + 3 // 8 (5+3)++ // 9 (8+1) - - // 8 (9-1)++ // 6 (5+1)5-3 // 2-3 //
-
. -
-
34 1. JavaScript
, . ,
"" + "" "". . -
NaN -, ( . 1.7.3. , , -
.
= " " // " " = "" // ""z = + " " + // z " "z = + 5 // z " 5 " = "20" + 5 /* " 2 0 5 " ,
30 "30" */ -
(true 1, false 0), - . , -
, .
true + true // 2true + false // 1true * true // 1true/false /* Infinity (,
) */true + 5 / / 6false + 5 / / 5true * 5 // 5true / 5 / / 0.2
, , -
, -
.
"" + true // "Bacfltrue""5" + true // "Strue"
:
"" " true /* NaN ( , ) */
' true // 5"5" * false // 0"5" / true // 5
, -
. , -
, :
; -
(, );
-
1.5. 35
-
true false 1 , .
, JavaScript - , -
. , -
.
1.5.3. , -
= , -
.
+= X+-Y X = X + Y
X-=Y X = X - Y* X * Y X X * Y
/- X/=Y X = X / Y%= X%=Y X = X % Y
-
, -
.
, .
:
= ""
+= ", " // ", "
1.5.4. , - .
, - , -
Microsoft Internet Explorer Netscape Navigator. - .
,
, , . . -
, ( ), - , true false. , (-, ), true. false.
X = =Y X I - Y
-
36 1. JavaScript
> , X * Y ( ) X >= Y, X < Y
= "0.5" // truefalse < "57ab" // falsefalse > "57ab" // false
-
1.5. 37
true == "true"true != "true"true = "true"
// false// true// false// false
1.5.5. , ,
, -
. () , . , -
:
30 10, . , . -
true false.
! () !&& X & & Y|| X | | Y
! , : X true, ! false, , X false, ! true. , -
.
Y X && Y X 11 Y
true
true
falsefalse
true
falsetruefalse
true
falsefalsefalse
true
true
truefalse
&&
-
38 1. JavaScript
= false || 2*2==4 // true = 5
-
1.5. _ 39
if (age
-
40 1. JavaScript
switch -
if. - switch (). , ,
.
switch :switch () {
case !:
[break]c a s e 2 :
[ b r e a k ]
[default:]}
switch , - . , -
. () break default -, .
,
. break , -. default, , . -
switch, default .
switch . , switch. - , . -
,
. , , -
. , break, - , break. .
, = 2switsch (x) {
case 1:alert(l)
case 2:alert(2)
case 3:alert(3)
} 2- 3- . , - ( , ), break.
-
1.5. _ 41
= 2switsch (x) {
case 1:alert(l) ;break
case 2:alert(2) ;break
case 3:alert(3) ;break
} 2- .
, xlang , - . -
switch:switsch (xlang) {
case "" :wi ndow. open ("engl .htm") ;break
case "":wi ndow. open ("french. htm") ;break
case "" :w i ndow. open ("german. htm") ;break
default:alert("y ")
} window.openQ HTML-. , if:
if (xlang == "")window. open ("engl. htm")
else {if (xlang == "")
wi ndow. open ("french. htm") ;else {
if (xlang == "")window. open ("german. htm")
/ elsealertC'V ");
:
if (xlang == " " ) w i n d o w . open("engl . htm" )else { if (xlang == "") w i n d o w . open (" f rench . htm")else { if (xlang == "") wi ndow. open ( "german . htm")else a ler tC'Y ")
}I
-
42 1. JavaScript
1.5.7.
, . JavaScript : for, while do-while. , , for while. , , - while. , , .
for for () , . -
:
for ( [ ] ; [] ; [ ] ){
} , -
. ,
:
for ( [ ] ; [] ; [ ] ) {
}, for, , .
.
. -
if. , , .
.
. . ,
( ). - , for, -. ( - for). , , , . ,
.
. , i = 0 var i = 0. - . -
. , , -
, ,
i
-
1.5. _ 43
for (i = 1; i
-
44 1. JavaScript
break , - ,
.
break :for ( [ ] ; [!] ; [ ] )
i f (2){
break}}
continue (). , break, . , -
break, continue , -
, , .
break :f o r ( [ ] ; [!] ; [ ] )
if (2){
continue}}
while while ( , ) , - for, . :
while ( ){
} , -
, while. , , -
. .
( ) , , . .
while for, - , , -
. , -
( ). ,
for.
-
1.5. 45
.
/* var z = i = 2while (i = 2) {
Z = Z*X
// z
!./* ! */var z = 1if (n >1) {
i = 2while ( i
-
46 1. JavaScript
.
/* */var z = i = 2do{
z=z*xi++
Iw h i l e ( i 1) {
i = 2do {
z=z*i
// z
// z !
while ( i
-
1.5. 47
-
-
( ). -. ,
, .
. -
.
2 + 3 * 5 / / 17, 2 52
-
48 1. JavaScript
1.6. , -
, . -
, , -
. , JavaScript , .
JavaScript , -, . ,
, , .
,
. -
.
, function, , . -
1.6.2. ,
:
_ () , -
. .
.
.
1.6.1. JavaScript ( ). - , , -
, ( ) .parselnt(crpoi
-
1.6. 49
parseFloat ( " 1 9 5 2 " ) // = 1952p a r e s e F l o a t ( " l . 5 0 p x " ) // = 1.5p a r e s e F l o a t ( " " ) // = NaN
i s N a N () true, - , false.
isNaN(123) / / falsei s N a N ( " 1 2 3 " ) / / falsei s N a N ( " T e n . 1234567") / / truei s N a N ( " 3 5 p x " ) / / trueisNaN(true) / / falseisNaN(fa lse) / / falsei s N a N ( " B a c f l " ) / / true
1.3, .
eval(cTpoKa) ; JavaScript ( HTML).
var = 5 // 5var = "if(y
-
50 1. JavaScript
escape("How do you do") // "How%20do%20you%20do" ' " ) /* %u041F%u0440%u0438%u0432%u0435%u0442 */
escape() unescapeQ - 2.8 ( 2).typeOf(o6beKT) ,; "boolean", "function" . .
1.6.2. , ,
, . -
(), function. , - :
function _()I
} :
function _() {
}function _() { }
, . -
JavaScript. - . () - . ,
. ,
() . , -
. , -
. , -
.
, ( -) () , . , -
function, . , , -
.
, , -
return , . -
: , .
return . ,
-
1.6. 51
, return . - .
, -
( ). Srectangle. :
function Srectangle(width, height){S = width * heightreturn S}
width height, S, return .
Srectangle , - S:
function Srectangle(width, height){return width * height}
, , , -
, ( ) . , ,
. :
_ () ( ) . , ,
,
.
-
, -
.
JavaScript . , ,
, ,
null. , .
SrectangleQ, , .
, -
SrectangleQ, ,
, , .
Srectangle(3, 5) /* 3x5 */
-
52 - 1. JavaScript
Srectangle(3, 4 + 2 ) /* 3x6 */
height = 8Srectangle(3, height) /*
3x8 */
width=4height=5Srectangle(widt, height + 2) /*
4x7 */Srectangle(2) /* 0 (
) */ , -
, var. -
.
, .
1. . () , -
. ,
.
2. . ,
,
.
var -
, ,
, .
var ,
, . -
, var .
, -
,
, .
, -
,
, -
. , -
, ,
, .
, ,
.
1. S , - :
-
1.6. 53
function Srectangle(width, height){5 = w i d t h * heightreturn S>z = S r e c t a n g l e ( 2 , 3) /* z S ;
S - */2. 5 , -
:
function S r e c t a n g l e ( w i d t h , height){S = w i d t h * heightreturn 5}5 = 2z = Srectangle(2, 3) /* z 6,
5 2, ; */
3. , 2, vanfunction Srectangle(width, height){var 5 = width * heightreturn S}var S =2z = Srectangle(2, 3) /* z 6,
S 2, ,
*/4. :
function Srectangle(width, height){var S = width * heightvar x = 17return S}z = Srectangle(2,3) /* z 6;
S ;
*/5.
:
function S r e c t a n g l e ( w i d t h , height){v a r s = width * heightw i d t h = width + 10 // widthreturn sIwidth = 2height = 3z = S r e c t a n g l e ( w i d t h , height) /* z 6;
w i d t h 2, */
, .
: , - , ,
-
54 1. JavaScript
, , --
.js. - , -
.
! . , , -
. ,
! -: 1*2*3*...*,
-
1.7. 55
, -
,
.
Function, - . ,
arguments, , . ,
, .
arguments. , 1.7.7.
1.6.3. , . -
JavaScript . , -
.
1. Srectangle(width, height) , width height. b - :
S3 = 0.5* Srectangle(a, b) -
. -
S3.2. :
if (Srectangle(a, b) > Srectangle(c, d))alert(" ")
3. :v a r = " 2 5 "var = 12var S = Srectangle(parselnt(x) , )
.
1.7. ,
.
, . JavaScript . , .
, .
, . -
, JavaScript,
-
56 1. JavaScript
HTML- . .
.
: . -
. .
. , -
.
. ,
.
,
, : _.. ,
.
.
. -
: _.(). , .
, , -
, , -
. -
, .
,
- -. , -
-, . -
.
, , -
, , . ,
, ,
, , .
. , .
JavaScript , , -
. - String (), Array (), Math ( ) Date (- ). . , , . -
, , -
. () -, .
, -
. -
. -
, .
, Math, Array, -
-
1.7. 57
, -
Array. , , prototype (), - -
. , , -
.
, . ,
-
, , -
. - ,
JavaScript .
1.7.1. String () String . , , , -
, ,
. .
String . -
. -
() , .
:
_ = new S t r i n g ( " _ " ) _ . ,
mystring = new 5("!") mystring "!". -
:
_ = "_"
var _ = "_"
-
:
.
String.
. ( [ ] )S t r i n g . ( [ ] )
, -_
. ,
, , , -
.
-
58 1. JavaScript
String , , ,
, , , -
( String). length - , ( ).
m y s t r i n g = " "mystring.length // 30" ". length // 30
function fstr ingO {return "abcde"} /* , "abcde" */
fstr ingO.length // 5 -
. .
Stringlength , , ( ) ; .
"". length // 4"".length /* 11
(\ - ) */ = "" // .length // 0 ( 0)
prototype (), - , -
.
-
. .
function myFuncO { // return ""I
// myName :String.prototype.myNameO = myFuncmystring = " - " + " ".myNameO
/* mystring " - " */
String 1. charAt(nHfleKc) , -
.
: .11() .
() , 0.
-
1.7. 59
"".charAt(2) // """".charAt(15) // ""mystring = ""mystring.charAt(mystring.length-1) /*
"" */2. charCodeAt([MHfleKc])
().: . ]) .
IE4+ NN6 Unicode , NN4 ISO-Latin 1.
"abc" . charCodeAtO // 97"abc" . charCodeAt(l) // 98"abc" . charCodeAt(25) // NaN" " . charCodeAt(25) // NaN" " . charCodeAt(0) // 1103
3. fromCharCode(HOMepl [, 2 [, ... ]]) , .
: String.fromCharCode(HOMepl [, 2 [,... ]]) .
IE4+ NN6 Unicode, NN4 ISO-Latin 1.
S t r i n g . f r o m C h a r C o d e ( 9 7 , 9 8 , 1 1 0 2 ) / / ""4. concat(crpoKa) () .
: !.1(2) .
, + : ! 2.
" " . c o n c a t ( " " ) // "" = "" + " " // " " . c o n c a t ( " " ) // " "
5. indexOf(cTpoKa_noMCKa [, ]) , -, .
: '^(_ [, ]) .
_
. ( ) 0. - , -1. -1. 0. , , ,
.
-
60 1. JavaScript
substr()(. ), - .
.
=" "
. i n d e x O f ( " " ) / / 3 . i n d e x O f ( " " ) / / 3 . i n d e x O f ( " " ) / / -1 . i n d e x O f ( " " ) / / 0 . i n d e x O f ( " " ) / / 6 . i n d e x O f ( " " , 7) / / 19x . i n d e x O f ( " ") // 2 . i n d e x O f ( " " , 5) / / 9 . i n d e x O f ( " " ) / / 0
6. LastIndexOf(cTpoKa_noHCKa [, ]) , -, ; - ,
, 0.: .LastIndexOf(crpoKa_noMCKa [, ]) . indexOfQ - .
=" "
. l a s t l n d e x O f ( " " ) // 3x . l a s t l n d e x O f ( " " ) // 30 . i n d e x O f ( " a " ) // 15
7. 11() Unicode, .
: !. 11(2) . : IE5.5+, NN6+. , 0. ! -, 2, , -.
. . ,
IE5.5 IE6.0 1 -1, a NN6 Unicode.
8. (1 [, 2]) , , -
.
: .$(1 [, 2]) . .
, -
! . . 0. , - !
-
1.7. 61
2, . , .
slice() substr(). - substringQ.
= " "
.slice(3,8) // "".slice(3,-2) // " "
/* */ = "mumuisigerasim.ru"i = . i n d e x O f ( " @ " ) // 4_name = x . s l i c e ( 0 , i) // "mumu"_domen = x.s l ice( i+l , . i n d e x O f ( " . " ) ) // " g e r a s i m "_domen = .s l ice( i+ l , -3) // " g e r a s i m "
9. [, ]) , .
: . [, ]) .
, -
. , -
, , ,
.
, .
= " "
x.split(" ") /* - : "", "" */ . s p l i t ( " " ) /* - : "", " ", "" */ . s p l i t ( " " , 2 ) /* - : " " , " " */
10. substr(nHfleKC [, ]) , .
: .substr(nHfleKc [, ]) . .
, _ -
! . . 0. , - 1 , . sliceQHsubstr ingQ.
= " "
.substr(7,4) // ""
/* */ = "[email protected]"i = .indexOf("@") // 4_name = x.substr(0, i) // "mumu"_domen = .substr(i+1) // "gerasim.ru"
-
62 1. JavaScript
11. substring(MHfleKd, 2) , - .
: .5$(1, 2) . .
: .
. 0., ,
. substrQ sliceQ.
= " "
. s u b s t r i n g ( 0 , 6 ) // ""x.substring(7, .length) // "" . substr ing(7, 250) // "" . substr ing(250, 7) // ""
12. toLocaleLowerCaseQ, toLowerCase() .: cTpOKa.toLocaleLowerCaseQ, CTpoKa.toLowerCaseQ . IE5.5+, NN6, - .
, , -
. , -
, (, ).
= ""
. toLocaleLowerCaseO // "" . t o L o w e r C a s e ( ) // "" = ""
== // false . to l_owerCase() == . toLowerCase // true
13. toLocalellpperCaseQ, toUpperCase() .: CTpoKa.toLocaleUpperCaseQ, crpoKa.toUpperCase() .
IE5.5+, NN6, -.
, , -
. , -
, .
= ""
. toLocaleUpperCase() // "". toUpperCaseQ // "" = ""
== // false. toUpperCaseO == . tollpperCase // true
-
1.7. 63
String , - -
HTML. - - . , - " !" , HTML- :
! JavaScript, :
" !" .bold() boldQ . ,
. , write() document HTML-. - HTML- (. 1.11).
= " !".bold()document.wri te(x)
JavaScript
\. - Miuiosolt tntetnet
1: - ! 8
!
JavaScnpt
. 1.11.
document writeQ. .
, HTML. , , , -
( ). , - :
.() .
.
-
64 1. JavaScript
("_") 1 */
" " . l i n k ( " h t t p : / w w w . a d m i ra l . ru/~dunaev")/* HTML-:
< / > */
. -
-
, .
String . , .
. ,
, insstr. : si, s2 . :
function insstr(s l ,s2 ,n) {return s i .s l ice(O.n) + s2 + s l .s l ice(n)}insstr ("., " , " ", 7) // ", "i n s s t r ( " , " , " ", 100) // ", "
,
. replacestr. : si, s2 s3, s2 si (s2 - si )., s2 si. s2, - . si - s2, s3. . -
:
function replacestr(si, s2, s3) {var s = " // while (true) {
i = si.indexOf(s2) // s2 siif (i >= 0) {s = s + sl.substr(0, i) + s3 // si = sl.substr(i + s2.length) // }else break
-
1.7. 65
return s + sx}replacestrC'bacdae" , "a" , "X") // "bXcdXe"
x = " "replacestr (x , "" , "") // " "
, s2 , - , .
, .
, s2 ? -, si , -, , .
. , :
function replacestr (si, s2, s3) {if (s2 == "")s2 = " " // var s = " // while (true) {
i = si. indexOf (s2) // s2 siif (i >= 0) {
s = s + sl.substr(0, i) + s3 // si = sl.substr(i + s2. length) //
}else break // >return s + sx
} (insstrQ replacestrQ) , .
-
.js, . - , . -
.
(, ) - .
, JavaScript .
( .js). . -
. , -
" ".
, : -
. , -
. , N , - N " " . , -
-
66 1. JavaScript
. i, - , , .
, , -
" ". , ,
String, . ItrimQ, - .
function Itrim(xstr){if (!(xstr.indexOf(" ") == 0))
return xstr /* , */
var astr = xstr. split(" ") // var i = 0while (i < astr.length){
if (!(astr[i] == ("")))break /* ,
*/i++
}astr = astr.slice(i) // return astr.join(" ") // }
rtrim() -. , . -
, .
function r t r i m ( x s t r ) {if ( ! ( x s t r . l a s t l n d e x O f ( " ") == xstr. length - 1))
return x s t rvar astr = xstr.split(" ")var i = astr.length -1while (i>0){
if (!(astr[i] == ("")))break
i --}astr = astr.slice(0, i+1)return astr.join(" ")}
, , -
:
y s t r = r t r i m ( l t r i m ( x s t r ) ), trim(), :
function tr im(xstr) {return r t r im( l t r im(xstr))
;
1.7.2. Array () . -
,
. , -
-
1.7. 67
. ( ). ( ) . -
(). - , 0, , .
-
, . -
, -
, , , .
.
new:
_ = new Array([_]) _ , -
. , -
, .
, nul l ( ). , -
. ,
new Array () Array. Array length, -. , -
_.length. , ,
. -
, . ,
: _[]. - .
earth, - . ,
( ).earth = new A r r a y ( 4 ) // 4- earth[0] = ""earthfl] = "24 "earth[2] = 6378earth[3] = 365.25earth.length // 4
, , , -
earth [2].
Array.
earth = new Array("", "24 ", 6378, 365.25)
-
68 1. JavaScript
JavaScript , - , , .
,
earth = new A r r a y O // earth.xtype = ""earth.xday = "24 "earth.radius = 6378earth.period = 365.25
, -
earth.radius. : earth["radius"]. .
, , .
. -
, , , .
, -
.
:
_[_1] [_2] , , -
: - , .
. -
, . -
. , -
. -
. -
, . , "
2.1" 1- , 2- .menu = new A r r a y Omenu[0] = new ' 1.1", " 1.2", " , " 1.3")menu[l] = new ' 2.1", " 2 . 2 " )menu[2] = new ' 3 . 1 " , " 3 . 2 " , " 3 . 3 " , " 3 . 4 " )
2- 3- , :m e n u [ 2 ] [ l ] / / " 3 . 2 "
,
, :
menu = new A r r a y O/* : */menu[0] = new A r r a y ( " ! " , " 2 " , " " )menu[l] = new A r r a y Omenu[l][0] = new ' 1.1". " 1.2", " 1.3")menu[l][ l] = new ' 2 . 1 " , " 2 . 2 " )m e n u [ l ] [ 2 ] = new ' 3 . 1 " , " 3 . 2 " , " . 3 " , " 3 . 4 " )
-
1.7. 69
menu[0][ l ] // " 2"m e n u [ 0 ] [ 2 ] / / " 3"menu[l][1][0] // " 2.1"m e n u [ 1 ] [ 2 ] [ 3 ] // " 3 . 2 "
,
. ,
, , . -
. -
, -
, .
= new A r r a y ( 5 , 2, 4, 3) = // [2] = 25 // 2[2] // 25, [2]
.
, , -
,
,
, :
= new ( 5 , 2, 4, 3) = new ArrayO // for(i=0; i
-
70 1. JavaScript
m y a r r a y . a u t h o r = " " /* author myarray */
xarray.author = "" /* author xarray */
. -
Array.
. aSum(), - .
. . -
, Sum - aSum():
function a S u m ( x a r r a y ) {var s = 0for(i = 0; i
-
1.7. 71
= new arrayd, 2, "")a.join(" ") // - "1 2 "
3. () .: _.() . : IE5.5+. .
4. 5(|) .
: _!.5(|) . : IE5.5+. .
5. shiftQ .: _.shiftQ . : IE5.5+,NN4+. .
6. 51'1(|) .
: _.5|): . : IE5.5+. .
7. reverseQ -.
: _.() . .
= new a r r a y ( I . 2 , " " )a . r e v e r s e O /* :
"" , 2, 1 */8. 5$(1 [, 2])
.
: _.55(! [, 2]) . .
( ) , - . ,
! . - ! 2, - . .
= new ( 1 , 2, " " , " " , " " ).slise(l,3) // : 2, ""a.slise(2) // : "", "", ""
-
72 1. JavaScript
9. 50|1([_]) () .
: _.5:([_]) . .
, .
,
ASCII- . , . , 357 - , 85, , . . -
, sortQ .
,
sortQ . ( ) . ,
, , -
. , , . -
(, 0 ), - , sort() :
,
-
1.7. 73
= new A r r a y ( " " , " " , " " , 12, 5) = a.spli(1,3) /* : "", "", 12
- : "", 5 */ spliceQ -, , , .
, -
. spliceQ - (), () . -, ,
,
. spliceQ , - ,
. , 0.
= new A r r a y ( " " , "", " " , 12, 5) = . s p l i ( 1 , 3 , " " , " " , " " )
// - : "", "", 12/ / - : "","", ", "",5
= new Array("", "", "", 12, 5) = a.spli(1,0,"", "", "", "", "")
// - /* - :
"", "", "", "", "", "" */H.toLocaleStringO, toString()
.
toLocaleStringQ IE5.5+ NN3+, toStringO . toLocaleStringO .
join().
-
, : , , -
. , -
.
, :
function S(aN){var S=aN[0]for(var i = 1; i
-
74 1. JavaScript
, :
function Nmin(aN){var Nmin = aN[0]for(var i = l ; i
-
1.7. 75
-
, , .
, . , , -
. , , -
, . . .
JavaScript . . , .
, -
. ,
, ,
.
2 + 3 111 2 + 3.6 // 5.6 2.4 + 3.6 // 6 - 6.00 //
,
: !2 !2. 110*">}.
15 // 100 00026 // 2 000 0001.5 // 1500+1.5 // 1500-1.5 // -1500-4 // 0.0003
JavaScript , : 10 (), 16 (-) 8 (). -, ,
, .
( ), , ,
: , 1, 2,..., 9, , , , d, e, f ( ). , Ox4af 1199. , -
0 7. , 027 ( 23). -
, .
. -
to!6() , ,
. , 255 ( ).
function tol6(nlO) {hchars = "Q123456789abcdef" / , 16- if (!0 > 255) return null
-
76 1. JavaScript
var i = n!0%16var j = (nl0 - i)/16rezult = "0x"rezult += hchars .charAt ( j )rezult += hchars . charAt (i )return rezult
to!6(250) // "0xfa"to!6(30) // "0xle"to!6(30)+10 // "0xlel0" - , parselnt(to!6(30)) + 10 // 40
, += = + .
to!6() :function to!6(n!0) {
hchars = new Array ("0", "1"a", "b", "c", "d", "e", "f"}
if (n!0 > 255) return nullvar i = n!0%16var j = (n!0 - i)/16rezult = "0x"rezult += hchars[j]rezult += hchars [i]return rezult
"2", "3", "4", "5", "6",
. to2()
, , . -
. to2() - . , var - - , .
function to2(n!0) {if (n!0
-
1.7. 77
parselnt("010", 10) // 10parselnt("010" , 2) // 2parselnt("010", 16) // 17
, parseFloatQ IE6.0 , - ( ). , , -
.
"" + 25.78 // "25.78""" + 2 . 5 // "2500"
Number
, Number . - , .
N u m b e r : = new Number()
-
:
.
Number..[])Number,([])
Number MAX_VALUE ,
JavaScript (1.7976931348623157+308). M I N _ V A L U E ,
JavaScript (5-324). NEGATIVEJNFINITY - , , Number.MIN_VALUE. POSITIVEJNFINITY - , , Number.MAX_VALUE. NaN , N a N , JavaScript -
, (, ) (Not a Number).
prototype (), , - String (. ).
Number Number , , .
1. toExponential(KOflM4ecTBo) .: ) . : IE5.5+, NN6+. , ,
.
-
78 1. JavaScript
x=new Number(456)x.toExponential(3)x.toExponenttal(2)x.toExponential(l)x.toExponential(O)
2. 1:1() - .
: 11() . : IE5.5+, NN6+. , ,
.
x=new Number(25.65)x . t o F i x e d ( 3 ) / / 25.650x . t o F i x e d ( 2 ) / / 2 5 . 6 5x . t o F i x e d ( l ) / / 2 5 . 7x . t o F i x e d ( S ) / / 2 5 . 7
3. toPredsion(T04HocTb) - .
: .toPrecision(io4HocTb) . : IE5.5+, NN6+. , , ,
, .
x=new Number(135.45)x.toPrecision(6) // 135.450x.toPrecision(5) // 135.45x.toPrecision(4) // 135.5x.toPrecision(3) // 135x.toPrecision(2) // 1.4e2x.toPrecision(l) // Ie2x.toPrecision(Q) //
4. 151:([]) .
: .1:5([]) . , -
. 2 16 -. , .
x=new Number(127.18)x. toStr ingO // "127.18"x.toStr ing(10) // "127.18"x.toStr ing(16) // "7f .2el47ael47b"x.toStr ing(S) / / "177.134121727024366"x=new Number(5)x . t o S t r i n g ( 2 ) // "101"
-
1.7. 79
1.7.4. Math () Math (, ) . Math - :
Math.Math.()
Math Math .F LN10 10LN2 2LOG10E ( )LOG2E PI SQRT1_2 - 1/2SORT 2
,
Math.var R = 10 // circus = 2*R*Math.PI //
Math () ( ) ; $() ; 51() ; atan(4HOio) ; atan2(x, ) ; cei(.() ; $() ; () ; () ; 1() ; (1,2) !, 2; 1(1,2) !, 2; \/(!,2) ! 2; random() 0 1; !() ; sin () ; sqrt(4Mcno) ; 1() .
-
80 1. JavaScript
1. randomQ , 0 1. 0 Nmax, :
= N m a x ' M a t h . r a n d o m f ) N m i n Nmax, :
= Nmin + (Nmax - Nmin)*Math.randomO
:
function rand(a, b) {return a+ (b-a)*Math.random()
} , , -
() -, - . .
2. sin(x), - , :
Math.s in(Math.PI*x/180)
JavaScript -, . -
, -
.
, .
. , . -
xl 2 . ,
2 + + 0. { 2
2 + + = 0.
,
. ,
. -
.
. , -
, . -
. , .
, , ,
. , ,
, .
, ( beqQ) a, b . . , ,
-
1.7. 81
. .
,
. , -
, (null). :
function beq(a, b, ){ // var aret = new A r r a y Ovar D = b*b - 4*a*cif (a == 0) {
if (!(b == 0)){a r e t [ 0 ] = -c/baret[ l ] = null
} .return aret // }
if (D == 0) { // a r e t [ 0 ] = - b / 2 / aaret[ l ]=aret[0]
}i f (D>0){ //
aret[0] = (-b - M a t h . s q r t ( D ) ) / 2 / aaret[ l ] = (-b + M a t h . s q r t ( D ) ) / 2 / a
}r e t u r n a r e t}
:
beq(0, 2, 6) // (-3, null)beq(l, -2, 1) // (1, 1)beq(3, 4, -2.5) /* (-1.797054997187545,
0.4637216638542114) */beq(2, 0. 5) //
/ () b , = f(x), () , (/) - b (). -. , , ,
, .
,
. -
, -
, . -
. ,
, -
.
.
.
. ,
, . : -, .
-
82 1. JavaScript
. : -
ab , , . -
. , ,
.
,
.
.
? - eval(), JavaScript, - . integralQ - , f(x), , "5** + 10". - , -
. integralQ:function integral(expression, a, b){ // v a r x , yl, y 2 , n , length, d x , 5 = 0length = M a t h . a b s ( b - a)n = 100 // dx = length/n // = /*
*/yl = eval(expression) = + dx2 = eva l (express ion)S = (yl + y 2 ) ' d x / 2for( i=2; i
-
1.7. 83
return 0if (a == b)
return 0var x, yl, y2, n, length, dx,S=0length = Math.abs(b - a)yl = Math.min(a.b) // b = Math.max(a, b) // = yln = 100if (length>2) n=Math.round(100*Math.log(length+l))dx = length/n // x = a /*
*/yl = eval(expression)x = + dx2 = eval(expression)S = (yl + y2)*dx/2for(i=2; i
-
84 1. JavaScript
return 0var x, , dxdx = 0.000025x = a - dx // 1- = eval(expression)x = a + dx // 2- return (eval(expression) - y)/2/dx)}
:
Dydx("x",l) // 0.9999999999998899 ( 1)Dydx("x*x", 1) // 1.9999999999997797 ( 2)
() f(x) (0, /0), , ^ /(:)
. -
, .
extremumQ, , ( ). ,
, , 0. , -
eval(), -, . extremumQ , , -
, "5** - 2*". ,
0. , . -
:
function extremum(expression, a, b, d){ // if (!d) d = 0.001var x, yl, y2, ix = ayl = Dydx(expression, a)i = 1while ((x
-
1.7. 85
,
, .
1.7.5. Date () , -
, , . .
. , -
, , -
.
, . -
, ( ), . , , - -
5 . , 19 . - ,
. ,
. -
(Greenwich Mean Time GMT). GMT UTC(Universal Time Coordinated ). , -
GMT. - , . -
. -
GMT. , -
( ). , -, GMT, , -, .
JavaScript 30.10.2002, , . -
Date. , 31 30 , - 366 .
:
= new D a t e ( [ ] ) , . -
, , -
(, ).
-
86 1. JavaScript
Date. :
= .
, , ,
:
= . ( _ ) :
xdate = new DateQ /* , */
Y e a r = x d a t e . g e t Y e a r ( ) /* Y e a r */
Y e a r = Y e a r + 3 / * Y e a r ,, , 3 */
x d a t e . s e t Y e a r ( Y e a r ) /* */
new DateQ, , .
:
new Date("Mecflu, , ::")new .(" , ")new Date(rr, , , , , )new Date(rr, , )new .() ,
. -
. . -
. ,
0 (). . - ( -). . - 10, , 0 (. 3:05:32). -
, .
,
, 1 1970 ( - 00:00:00). , , , .
Date ,
, Date (. 1.3). , - :
= new Date([]), () , : .([]).
-
1.7. 87
:
( get) - ( set). - UTC. (, -, , , , , ).
1.3. Date
getFuUYear( )getYear( )getMonth( )getDate( )getDay( )getHours( )getMinutes( )getSeconds( )getTime( )getMHliseconds( )getUTCFuLlYear( )getUTCMonth( )getUTCOate( )getUTCDay( )getUTCHours( )getUTCMinutes( )getUTCSecondsQgetUTCMilliseconds( )setYear(3H34)SetFuUYear(3H34)setMonth(3Ha4)setDate(3H34)setDay(3H34)setHours(3H34)setMinutes(3H34)setSeconds(3H34)setMiLliseconds(3Ha4)setTime(3H34)setUTCFuLLYear(3H34)
1970-.. .70-...0-111-310-60-230-590-590-...
0-...1970-.. .0-111-310-60-23
0-590-590-....1970-.. .1970-...0-111-310-60-230-590-590-...0-...1970-.. .
( = 0)
( = 0) 24-
1.1.70 00:00:00 GMT 1.1.70 00:00:00 GMT UTC UTC ( = 0) UTC UTC ( = 0) UTC 24- UTC UTC UTC 1.1.70 00:00:00 GMT ()
( = 0)
( = 0) 24-
1.1.70 00:00:00 GMT 1.1.70 00:00:00 GMT UTC
-
88 1. JavaScript
1.3 ()
setUTCMonth(3H34)setUTCD3te(3H34)setUTCDay(3H34)setUTCHours(3Ha4)setUTCMinutes(3H34)setUTCSeconds(3Ha4)setUTCMilliseconds(3H34)
getTimezoneOffset ()toDateString()
toGMTString()
toLoc3leDateString()
toLocaleString()
toLocaleTimeString()
toString()
toTimeString()
toUTCString()
D3te.parse("dateString")
Date.UTC(3H34)
0-111-310-60-230-590-59
0-...
UTC ( = 0) UTC UTC ( = 0 ) UTC 24- UTC UTC UTC 1.1.70 00:00:00GMT GMT/UTC ( ) (IE5.5)
-
(NN6, IE5.5)
-
(NN6, IE5.5)
(IE5.5)
GMT
, -
, -
, UTC. , , . -
UTC , . , , , , -
0. . - 11- , 12-, - . (Sunday) 0- , 7-. XX - 1900. , 1998 98. 1900 1999 . , 2002 -
-
1.7. 89
2002, 02 1902 . getFullYear() - .
, 2003 .today = new Date() // Y e a r = t o d a y . g e t Y e a r O // 2003today = new Date(98,11,6) /* today
6 1998 , 00:00:00 */Y e a r = t o d a y . g e t Y e a r O // 98today .getFullYearO // 1998
'
, set. .
, -
. .
.
mydate = new Date(1952, 10,6) // "Thu Nov 6 00:00:00 UTC+0300 1952"myday = mydate. getDayO // 6m y d a t e . s e t Y e a r ( 2 0 0 3 ) // 2003 myday = m y d a t e . g e t D a y O // 4
-
toString(). - . , Windows 98 Internet Explorer 5.5 , - , :
Thu Oct 31 13:16:23 UTC+0300 2002, , , 31, 13 16 23 , 3 , 2002 . ,
toLocaleString():mydate = new DateOmydate. toLocaleStringO // "31 2002 . 14:15:30"
15.5+ NN6+ :
mydate = new DateOmydate. toLocaleDateStr ingO // "31 2002 . "mydate.toLocaleTimeStringO // "14:15:30"
, ,
toLocalDateStringO toLocalTimeStringQ, - . -
-, , -
.
, -
. -
, , , . .
-
90 1. JavaScript
1. , :week = 1000*60*60*24*7 /*
- 604800000 */mydate = new Date() // mydate_ms = mydate.getT imeQ /* ,
1.01.1970 00:00:00 */mydate_ms += week // maydate_ms = mydate_ms + weekmydate.setTime(mydate_ms) /*
mydate */newdate = mydate. toLocaleStr ingO //
2. , 10 2003 5 2003. :datel = new, Date(2003 ,01,10)date2 = new Date(2003,02,5)
datel dateZ , (-, Mon Feb 10 00:00:00 UTC+0300 2003). -, parse() Date. Date.parse(date2) Date.parse(datel) :
days = ( D a t e . p a r s e ( d a t e 2 ) - D a t e . p a r s e ( d a t e l ) ) / 1 0 0 0 / 6 0 / 6 0 / 2 4/ / : 2 3
3. , - "..", 1 12, 0 11. , Date, - .
, strdate "..",
", , ". -
:
astrdate = s t r d a t e . s p l i t ( " . " ) /* , strdate */
/* */mydate = new D a t e ( a s t r d a t e [ 2 ] , astrdate[1]-1, a s t r d a t e [ 0 ] )
4. , , , ,
".. ::"
. , -
, , -
. , , -
.
, .
function mydate(strdate){if (strdate == "" || strdate == null) {
return new Date()}var astrdate = strdate.split(" ")
-
1.7. 91
if (astrdate.length == 1)astrdate[l] = "00:00:00"
a s t r d a t e [ 0 ] = a s t r d a t e [ 0 ] . s p l i t ( " . " )a s t r d a t e f l ] = a s t r d a t e [ l ] . s p l i t ( " : " )if (astrdate[ l ] . length == 1)
astrdate[ l ] = new A r r a y ( a s t r d a t e [ 1 ] [ 0 ] , " 0 0 " , " 0 0 " )else {
if (astrdate[ l] . length == 2)astrdatefl] = new Array(astrdate[ l ] [0], astrdate[1][1] , "00")
}return new D a t e ( a s t r d a t e [ 0 ] [ 2 ] , a s t r d a t e [ 0 ] [1]-1, a s t r d a t e [ 0 ] [2] ,a s t r d a t e [ l ] [ 0 ] . astrdate[1][1] , a s t r d a t e [ 1 ] [ 2 ] )}
, return - .
mydateQ :
datel = m y d a t e ( " 1 0 . 2 . 2 0 0 3 " )date2 = m y d a t e ( " 5 . 3 . 2 0 0 3 " )days = ( D a t e . p a r s e ( d a t e 2 ) - D a t e . p a r s e ( d a t e l ) ) / 1 0 0 0 / 6 0 / 6 0 / 2 4
, -, (-), - . , -
, .
, , ,
(). , setlntervalQ . - .
1.7.6. Boolean () Boolean :
= new 1(_) prototype, toStringQ Of(), String Number. prototype String Array. Boolean , , new Boolean, (prototype).
1.7.7. Function () Function :
function _() {
1
-
92 1. JavaScript
,
new Function. Function:
_ = new Function(["napl", [."napN"]. "!; [;]")
.
. , -
.
, Function, : _().
Srectangle = new Function("width", "height", "var s = width'height;return s")Srectangle(2, 3) // 6
var expr = "var s = width*height; return s"Srectangle = new Function("width", "height", expr)Srectangle(2, 3) // 6
a = " w i d t h "b = "height"expr = " v a r s = width*height; return s"Srectangle = new Funct ion(a, b, expr)Srectangle(2, 3) //
, new,
Function, .
Function1. arguments , .
0. , Array ( , length ). arguments , , . ,
, ,
("", 0, null) . . - .
: _.arguments.
, , , -
, -
( !).function m y f u n c ( a , b,c){var arglenth=myfunc.arguments.length /*
*/var x=""for (i=0; i< myfunc.arguments.length;i++) {
-
1.7. _ 93
+= myfunc . arguments [i ] + " , "}return x + " B c e r o : "+ myfunc . arguments . length)m y f u n c ( 5 , " " ) / / " 5 , , : 2 "myfuncO // ": 0"myf unc(null , " " ,0 ,25) // "null , , 0 , 2 5 , : 4"
2. Length , .: _. length arguments, - .
function m y f u n c ( a , b, , d){return myf unc . arguments . length}myfunc(a.b) // 2myf unc . length // 4
3. caller , -; , - null.: IE4+, NN4.: _. caller _. caller , - _.
function fl() {f2()}funct ion f2()alert (f2 .caller) // f2. caller
fl() f2(), , fl() (. 1.12).
. 1.12. fl() f2.caller
FunctiontoString() .: _.15()
-
94 1. JavaScript
-
.
function myfunc(a, b){return a*b/2}alert (my func.toStr ingO)
. 1.13.
IMiciosoft Internet fxptr.1. ; :
Iff f \ function myfijncfa, b)f
mssx*OK '' 1
.
. 1.13. alert(myfunc.toString())apply( [_ [, _]])call( [_ [ ,napl[ ,2[ n a p N ] ] ] ] )
.
. , -
,
. ,
.
1.8, . , .
,
. ,
. -
, 1.8.
/* - ()*/function c a r ( n a m e , model, color) {th is.name = name // this.model = model // his.color = color // t h i s . s h o w = showcar // I/* , car */function s h o w c a r ( ) {a ler t ( th is .name + "-" + this.model) // I/* car */
mycar = new c a r ( " " , " B A 3 2 1 0 5 " , " w h i t e " ) show car ( -) :
m y c a r . s h o w ( )
-
1.7. 95
showcarQ, . this, - .
apply() callQ showcarQ - mycar. , , showcar . showcar callQ, - mycar :
showcar.call(mycar) catlQ , . , ) applyQ.
1.7.8. ObjectObject , - JavaScript, String, Array, Date . . . .
1function _ ([napl,...[, napN]){
> = new _( ["napl",...[, " " ] )
2 = new Object(). =
3 = {!: ! [, 2: 2 [ N]}
:
__.
__.([]), , , -
, , , ,
. . , -
. -
:
function (, , , ) {this. = this. = this. = this. = }
,
. this , - . this, - -, . -
,
-
96 1. JavaScript
,
, . ,
agentOO?:agentOO? = n e w ( " " , 5, " 2 2 3 - 3 3 2 " , 3600.50)
:
007. // " "agent007. / / 3600.5
:
S h t i r l i t z = new ( " " , 4 , " 1 2 3 - 4 5 6 7 " , 4500.50) ,
. prototype, - String Array. toStringQ . -
hasOwnPropery("cBoiicTBo") , , - , ( prototype). , true, false. .
, ,
, .
1.8. , -
JavaScript . - new ,
. , prototype - ,
. -
, -,
.
. ? . -
, -
. - -
, ,
. -
( Array): .
, ,
. , . , -
, -
- .
- -
,
.
-
1.8. 97
1.8.1. JavaScript . .
,
.
, - -
. , , ? , - , . ,
.
- -
. -
. -
this (): this.. -,
() (), model () color ():function car(name, model, color) {
this.name = namethis.model = modelthis.color = color
} car. - , ,
. ,
new:
mycar = new ( " 0 " , "31111","white"), mycar, . - .
mycar :mycar.model // "31111"mycar.name // " "mycar.model = "311113" // "311113"
, -
( : .). new ObjectQ:
mycar = new O b j e c t Om y c a r . n a m e = ""mycar.model = "BA31111"mycar.color = " w h i t e "
: - Object, , , - Array. :
mycar = { : " 0 " , model:"BA31111", c o l o r : " w h i t e " } . =
= , -
.
-
98 1. JavaScript
,
, , -
( null, 0 ""). (- ||) :
function car(name, model, color) { // this.name = name || ""this.model = model || ""this.color = color || "b lack"
}mycar = new c a r ( " " , " " ) // mycar car
m y c a r . n a m e / / " "mycar.model // ""mycar.color / / "black"
1.8.2. -
, ,
prototype. (), - mycar, prototype owner() :
function car(name, model, color) { // carthis.name = name || "."this.model = model || ""this.color = color || "black"
}mycar = new car("","") /* mycar
car */mycar.name // ""mycar.model // ""mycar.color // "black"car.prototype.owner = "" // mycar.owner // ""
( ), -:
._ =
, -
.
function c a r ( ) { }mycarl = new car()mycar2 = new car()mycarl.name = ""mycar2.model = "BA32106"
mycarl.name // ""mycarl.model // undefined ( )mycar2.name // undefined ( )mycar2.model // "BA32106"
-
1.8. 99
1.8.3. .
: - , , . , -
photo, URL- . , -
, , -
photo. photo. photo , , -
photo.function car(name, model, color, photo) {
this. name = namethis. model = modelthis. color = colorthis. photo = photo
// car
// photo
function photo (name, url) {this. name = namethi s . url = url
// photo
, photo:photol = new photoC'OKa" , "/images/okal . j pg")photo2 = new photoC'OKa" , "/images/oka2 . gi f" )
car:
mycar = new ("0", "31111" . "white" . photol)mycar. photo. url // "/images/okal . j pg"mycar. model // "BA31111"
photo2)// "/images/oka2 . gi f "// "BA31111"
mycar = new ("0", "31111" , "white" ,mycar . photo . urlmycar. model
: URL- , mycar, urL photo, mycar , , - mycar.
1.8.4.
,
.
: name (), model (), regnum (), owner () photo (). , , , (, ). , , - . -
-
100 1. JavaScript
,
, , -
, .
: , (, URL- ). (, -, 32101 ), . -
ref:function ref(name, model, url) { /*
*/t h i s . n a m e = name // th is .model = model // this.url = url // URL-
} .
( aref). ref:
aref = new A r r a y O // aref[0] = new r e f ( " " , "2101", " p i c t 0 . g i f " )aref[ l] = new r e f ( " " , " 2 1 0 " , "p ic t l .g i f " )a r e f [ 2 ] = new r e f ( " B c w i r a " , " 3 2 4 " , " p i c t 2 . g i f " )a r e f [ 3 ] = new r e f ( " O K a " , "Basllll" , " p i c t 3 . g i f " )
.
. -
,
.
, ref., - :
function c a r ( r e g n u m , owner, ref) {th is.regnum = regnum // t h i s . o w n e r = owner // t h i s . r e f = ref //
} .
:
a c a r = new A r r a y Oa c a r [ 0 ] = new c a r ( " A 1 2 3 B X " , " " , aref[ l ] )a c a r [ l ] = new c a r ( " M 3 4 5 C T " , " " , a r e f [ l ] )a c a r [ 2 ] = new c a r ( " E 6 7 8 C A " , "", a r e f [ 0 ] )a c a r [ 3 ] = new c a r ( " K 0 5 6 0 X " , " " , a r e f [ 2 ] )a c a r [ 4 ] = new c a r ( " K 8 9 5 M X " , " " , a r e f [ 3 ] )a c a r [ 5 ] = new c a r ( " P 3 4 0 H Y " , "", a r e f [ 2 ] )a c a r [ 6 ] = new c a r ( " 0 3 2 1 0 K " , " " , a r e f [ 2 ] )
7 . 32106 ,324 , . - ,
.
:
-
1.8. 101
[4].ref.model[3] .ref.name[3].owner
// "31111"// ""// ""
,
Array () -. .
, ,
. HTML- , . ,
, , , . HTML- -, , - JavaScript. . . ,
.
JavaScript, , writeQ document HTML- . ,
. ,
HTML- . , (-) .
1.1 HTML-, . - . -
,
(. 1.14).
- - Microsoft Internet E
$
(;! ;JA123BX( ||45"
!| I
678
|5210
|^
:|
'
I I | : | 5| (
. 1.14.
-
102 1. JavaScript
1.1.
/* */function ref(name, model, url) {
this.name = namethis.model = modelthi s.url = urlIfunction car(regnum, owner, ref) {
this.regnum = regnumthis.owner = ownerthis.ref = ref
/* */
*/// // // URL-
/* */
// // //
aref = new ArrayO // aref[0] = new ref("", "2101", "pict0.gif")
, "2106", "pictl.gif")"324", "pict2.gif")
'Basllll", "pict3.gif")
aref[l] = new ref(""aref[2] = new ref("Bonra",aref[3] = new ref("",
acar = new ArrayO"A123BX""M345CT""E678CA""K0560X""K895MX""P340HY""03210K", ""
BORDER=1> "" Baee"
/* */for(i=0;i
-
1.9. 103
1.9. , Java-Script . , - -. .
.
1.9.1. () . -
,
32. - , .
, .
. . 1.4 - .
1.4.
,
,
,
&, |, ~ , -, . - -
: 0 1, 1 0. . 1.5 , &, |, .
1.5. &, |,X
1100
Y
1010
X&Y
1000
X | Y11i0
X A Y
0110
-
104 1. JavaScript
, 2&3 2, 2(3 3. , 2 10, 3 11. & 10, 2, | - , 3. , ,
. , 32 12, 11 ( 3) 1100, 12. 2 1., 6 110; 1 , .
1.9.2. (delete) ,
delete. :delete
-
, -
, .
myarray = new Array("","b"."","d")myarray.length // 4delete myarray[l]myarray.length // 4myarray[0] // "a"myarray[l] // undefinedmyarray[2] // "c"myarray[3] // "d"
delete -.
JavaScript, , .
(in) ,
. -
, .
. -
, true, false. , in ( if, switch,for, while, do-while).
1. , document, HTML--, writeQ. ,
-
1.9. 105
" w r i t e " i n d o c u m e n t / / t r u e2. .
function (, , , ) {this. = this. = this. = this. = Iagent007 = new (" ", 5, " 2 2 3 - 3 3 2 " )"" in agent007 // true" " in agentS07 // false
in 15.5+, NN6+.
(instanceof) , -
JavaScript. , , Array, String, Date . . - instanceof true false , , ( if, switch, for, while,do-while).
Array, - Object.
m y a r r a y = new A r r a y Qmyarray instanceof A r r a y / / trueA r r a y instance O b j e c t / / trueM y a r r a y instanceof S t r i n g / / false
in 15.5+, NN6+.
1.9.3. (?:) i f . . .else... : . ,
. :
? ! : 2 :
= ? ! : 2 !, -, 2.
d = new Date() = d . g e t D a t e Otypedate = (x%2 == 0)&&(x > 1) ? "" : ""
-
106 1. JavaScript
JavaScript , -, if, , , . :
function iff(condition, exprl, expr2){if (condition)
return eval(exprl)else
return eval(expr2)}
if, . . : -
, , -
. .
(tipeof) ,
: string, number , boolean, object, function undef ined. , typeof, . - . -
typeof.
var x = 3.14N = new Number(3.14)s = " !"a =new A r r a y ( l , 2, 3, 4, 5)function f(){}typeof xtypeof ntypeof Ntypeof stypeof atypeof f
'
//
"undefined""number""object""string""obj ect ""f uncti on"
1.10. , ,
, ; .
(. 1.6). , -
, . -
. .
, ,
, . JavaScript
.
-
1.10. 107
-
. , , -
.
, .
1.6.
!
function()
new
typeofvoiddelete
.
()
( ) ()
910
!1
12
,_
&
&&
( )
( )
() ()
-
108 1. JavaScript
1.6 ()
13 ? ( )14 =
%==
5=
& =
1_5 , ( )
, -
, , ,
. ,
,
, . ,
&& ; false, , , false. , || true, , , - true.
,
. - -
, , -
.
1.11. JavaScript, - , , ,
, (. 1.7). - , -
, - (, ) .
-
1.11. 109
interface , , . -
: myinterface, xlnterface . .
, -
, - -
. JavaScript - , .
,
. ,
.
,
. ,
( ) .
abstractbooleanbreakbytecase
catchcharclassconst
continuedefaultdeletedodouble
1.7. elseextendsfalsefinalfinallyfloatforfunctiongotoifImplementsimportininstanceof
intinterfacelong ,nativenew
nullpackageprivateprotectedpublicreset
return
shortstatic
superswitchsynchronizedthisthrowthrowstransienttrue
trytypeofvar
voidwhilewith
-
2.
, -
, JavaScript . , . 4 - , ,
, . -
,
3.
2.1. -, 1950 I960 , -- . -
, ,
, GO TO (- , ). , - . GO TO , . -
. -
, Assembler . -
3-5 . - , -
. , ? -
. , , .
80- , , -
.
1960 1975 -, FORTRAN ALGOL. - , -
. ,
,
-
2.1. 111
, .
,
. GO TO - , , , ,
-
. .
70- , - , , ,
.
. -
. -
. PL/I - .
. ,
: ,
, , . .
, . , -
, : ? - , -
.
1990 - - (). , . , -
, -
. , .
. , -
, .
(, , ), ,
. , -
, ,
. ,
, , , -
.
() . , - ,
.
.
C++. () , . - , -
. C++, , () . - (, Java Object Pascal), C++ - - -. -
-
112 2.
, C++, , -. , - , - . , -
, , , -
C++. , , JavaScript -, 1.5 - , C++. , - JavaScript, , .
, -
, .
90- , .
,
. , -
. , -
C++ . - . . -,
?, . ,
, . , ,
?. - , -
, -
. -,
, , . -
, .
, , ,
. , -
, .
. -
, , , -
,
. , -
, -
. ,
, , , -
.
, Windows,OS/2, Unix Linux, . (, ) - (, , .), . , -
, - ,
-
2.2. HTML 113
, . , -
.
, -
.
JavaScript , , -, , .
, , -
JavaScript. -, , - . .
, JavaScript, . ,
-
, .
JavaScript -, .
: JavaScript , , - HTML. , ,
. , HTML, , JavaScript - , -.
, , JavaScript, . -
, JavaScript, - .
, JavaScript Java . Java C++, , , .
2.2. HTML2.2.1. HTML - HTML (Hyper TextMarkup Language ). ,
, . -
, , , -
, . -
, -
. ,
(, Windows) HTML htm html, - -, Microsoft Internet Explorer Netscape Navigator. HTML , . - (< >). , -
-
114 2.
. , -
. (). - . , -
, .
:
< _ [1 [= ! ] . . . [ [= ] ] > , -
. (, ), (, NORESIZE ). , , -
. , picture.jpg. - IMG , SRC , a "picture.jpg" (-). ID , , - , .
,
. , -
Enter, . , -
.
. .
. , .
.
, , , , . , - , , , . , , . - , , :
< I M G SRC = " b a n n e r . g i f " > < / A >HTML- (HTML-), , . , , .
HTML- , - (, , ,). , (-). , , Tery , , , -
TYPE. HTML- -, (), (), () (), () ().
-
2.2. HTML 115
- ,Caiu
. 2.1 HTML- , - HTML-.
--.! -. * fs*
:
Web-
-
Ca(vr ;'
-
-
116 2.
2.2.2. HTML , , , HTML. ,
-. -, -
. -,
HTML- . -, - HTML-, , ( , - ). , , HTML- - ( ). -
CSS (Cascading Style Sheets ). - ,
, STYLE. -
. STYLE . - ,
. -
CLASS = _. ,
( ) , . , ,
CSS. top left, , , -
z-index . , top left , , -
. ,
( HTML-), z-index. , -
, HTML- . HTML- , ,Flash-, , . HTML- , - , -
, - HTML - . ,
, (scripts). - JavaScript. -. Microsoft Internet Explorer JavaScript VisualBasicScript, Netscape Navigator. JavaScript HTML- ? , HTML- -
. JavaScript HTML- . -
, 1. ,
-
2.3. , 117
, , .
.
2.3. , 2.3.1. , HTML-, . JavaScript. - , JavaScript, , , , -
. JavaScript, -, - -
, .
, . , ,
, .
, JavaScript . ? JavaScript, HTML-. . HTML-, - , HTML-. HTML-, -. ,
, .
, -
.
, ,
. , HTML--,
HTML-, -. HTML- . - , - .
.
. -
.
. . -
, . -
: . . , .
, . , -, . - , . , ,
HTML-. HTML- . HTML-, .
-
118 2.
, , - .
LANGUAGE ; :a "JavaScript", "JScript"; "VBScript", "VBS". L A N G U A G E , Internet Explorer JScript.
SRC ( URL-), . , HTML-, .
. . . //
< / S C R I P T >
. , Internet Explo-rer 4.0 Netscape Navigator 4.0 JavaScript 1.2. - JavaScriptl.5, InternetExplorer 6.0 Netscape Navigator 6.0. JavaScript L A N G U A G E , , . , ,
,
.
\
JavaScript Internet Explorer JScript. Internet Explorer L A N G U A G E = "JavaScript". Net-scape Navigator LANGUAGE = "JavaScript", LANGUAGE ="JScript" . , - , LANGUAGE ="JavaScript". , , , ( ). , JavaScript, , , , HTML-. . , -
. , - , , ,
( ), , . - :
< ! --
// //-->
, -
. JavaScript - --> HTML, . , , -
-
-
2.3. , 119
. , -
.
, , , . , JavaScript . ,
, , , js. ( ), - , HTML- - . , ,
HTML-. :< 1 _ >
function myfunc(){
}
< / S C R I P T > < / S C R I P T >< / H T M L >
HTML- () , . -
.
, -
, .
. 2.3.2. -
, . , , - . , -
, HTML-- .
HTML-:
function myfunc(){ . . .. . . myfuncO}
. . . function myfunc(){myfuncO . . .
}
-
120 2.
HTML- - : -. HTML- . , - myfuncQ , (), - . ,- , . ,
.
, -
( ):
function myfunc(){ myfuncO
} function myfuncOfmyfuncO }
, ,
HTML-, HTML-. ( - ). . , HTML-, . -,
HTML-. -, -- onload , HTML--. onload , - . , ,
, HTML- . , - onload , -
, . :
function myfunc () {
!
-
2.3. , 121
2.3.2. ( ) HTML- , -
, ,
, . . HTML - , , -
.
. ,
. , onclick; onchange; onmouseover , HTML-. - . - HTML -, , . , -
HTML- , , myfuncQ:
< / 2 > ,
. ,
-. , , -
. .
, -, , ,
. .
onclick myfuncQ. , - .
function _(){
function _1).(){
. 2.2.
-
122 2.
< 2 o n c l i c k = " v a n x = 5; = + m y f u n c ( ) " > < / 2 > , -
. -
(. 2.2).1. HTML- , , .
SRC. onclick - clickimageQ, - . - picture.jpg :
function c l ick imageQ {alert("!")}
< / S C R I P T >
< / H T M L > 2:
< / H T M L > HTML-- , -
-. ,
.
, Java-Script, - "javascript:". -, . -, JavaScript.
2. . - , , HTML - ID (). ,
. ID , -. -
, :
_10.()
< H T M L > ! < / 1 >
function Myheader.onclick(){alert("!")}
-
2.3. , 123
, HTML- ID, .
. ,
, .
.
, -
:
HTML- , -- .
-
.
, ,
, -
-:
function document . () {
function document . onclick () {
} ( -) - - . , -
IE 4.0 . FOR E V E N T . FOR , , E V E N T . , -
ID.
alertC'Bbm ")< / S C R I P T > < / H T M L >
, EVENT, , FOR. - () .
- -
.
.
, (- ), .
-
124 2.
2.4.3 - .
2.3.3. , ,
. , -
-. , -
. -
- .
HTML-, . -, , . -
,
HTML- . , ( HTML-), .HTML- . window, a HTML-, , document. . , document window. HTML- , document. - , .
,
, .
1 JavaScript , . ,
. , -
, , .
:
.
.() (). , - , . , -
- , .
, . ,
.-
, :
!.2. . . . ( ), :
! . 2 . . . . o e N . ! . 2 . . . . .
( , - ). , :
( ); (-); ( , ).
-
2.3. , 125
document window, HTML-, () , - : window.document. document write(crpoKa), HTML- , HTML. , : window,document. write(cipoKa).
-
window
document
!window j
11-
-
-
-
126 _ 2.
, , HTML- - . ,
, . , window. , , location URL- screen . document, window. , HTML-, -, ( , , ) . . 2.3, -
. , , ,
. -
. HTML .
-
. ,
. , -
, -
HTML-. - . ,
. length . , ,
images, forms, - links. . , all. (, images), all. all . . -
, .
. ,
, , window , document. - :
document.iwieKL(Mfl.id_o6beKTa;
id_o6betaa ID , - HTML- . _ , - .
0. HTML- ID , .
, (, , ) NAME.
ID. , , - N A M E ( ), , ID:
-
2.3. , 127
document._ , , , . all. :
document._.elements[_]document._.elements[id_3neM6HTa]document._. _
_ ,
; 0. , InternetExplorer . HTML- -, , , -
.
-
CaUT
INPUT TYPE = "text" VALUE = "">
< / >
< / F O R M >< / H T M L >
. 2.4 - . ID( NAME), . , -, ( )
d o c u m e n t . i m a g e s ( 0 ) / / i m a g e s . -
, ( forms(O)), (15(_)). - , :
d o c u m e n t . f o r m s ( 0 ) . e l e m e n t s ( l ) / / .
links. links ., links(O) links. - HTML- :
document.l inks(0) , , -
all. .
ID HTML-, , all , - , . -
, .
, HTML-. , . , -
-
128 2.
Web-
-IMG SRC='pictjpg'>
HREF = 'www.admiral.ru/~dunaev'>CaiiT
-
2.3. , 129
HTML- , - . 2.5. , alertQ, HTML-. all. , document.all(5) HTML-, - . , , ,
, , all
(50 '(-
Web-Microsoft Internet Exploie
,v 0 HTML"V 1HEAO
2 TITLE
':...;., .;....; ;;.v...1:..'1.
/FORM8IWPIJT3P10 BUTTON11 SCRIPT
.'$
. 2.5. HTML- all
, ID, .
, HTML- , - . , ,
ID (. 2.6). ID, id . HTML- 2.2.
2.2. ID
-
CaUT
< / F O R M > &
-
130 2.
2.2 ()
msg = " "for(i =0; i
-
2.4. 131
,
, ID SRC. - id src . - :
document. images(0). id / / "myimage"d o c u m e n t . i m a g e s ( " m y i m a g e " ) . i ddocument.a l l ("my i m a g e " ) . i ddocument.al l .my image. idv a r x = document.al l .myimage // x . i d / / " m y i m a g e "d o c u m e n t . i m a g e s ( Q ) . src /* U R L , ,
f :///:/%20/^. jpg */d o c u m e n t . i m a g e s ( " m y i m a g e " ) .srcdocument.all("my image").srcdocument.a l l .myimage.srcvar x = document.a l l .myimage // x . s r c /* URL, ,
f i l e : / / / : / % 2 0 / 1 c t . j p g */ .
-
- . ,
(, - src). , .
2.4. ( , . .) , . - (, Windows) , -, . , ,
, -
, Windows , -, ,
. - ,
. -
HTML-, - . HTML- . -
.
2.4.1. , -
. , -
. , , , -
, ,
. ,
, (, , -, . .).
-
132 2.
, -
. ,
, -
. , -
( ). . -
-
, .
event, window. , , - , . event -
, -. -
event. HTML-, . -
event (. 2.7). , - , -
. keyCode Unicode. Unicode ASCII . - keyCode null. , keyCode , . - onkeydown onkeyup, on keypress.
Microsoft Internet Enplorei
"UMr.JMhl.Mri-!.
_J1
. 2.7.
function test .onclickC){var str=""str += "x = " + window.event.x + "\n"
-
2.4. 133
str += " = " + window.event. + "\n"str += " : "if (window.event.shiftKey){str += "Shift"}if (window.event.ctrlKey){str *= "Ctrl"}if (window.event.altKey){str += "Alt"}alert(str)}function test.onkeypressO{alertC'Kofl : " + window.event. keyCode)}
IE 4.0 button srcElement. button , , - (. 2.1).
2.1. b