版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
JavaScript.1.
.Thau!
-CGI一
Javascript,___CGI一
avascript-WEB_
JavascriptJavascript,-
-Perl,C1C++Java,Javasript.
Page1:Javascript.
Page2:.
Page3:.
Page4:.JavaScript
Page5:.
2.:.
.Thau!
-3Javascript.Javascript
JavascriptQ
jf-then-
JavasriptJava
JavascriptJavascriptJavascriptJavascript-3.0—30.
-Javascript.
Javascript
.1.:Javascript.
2.
3二.
.4:^JavaScript
.5:.
.3.:.
.Thau!
JavaScript.</title>.</head>.
.HTMLJavaScript-HTMLJavaScript.HTML_
JavaScript.
<scriptlanguage="JavaScript">.
-language二〃JavaScript”
JavaScript一
—[**z.
alert("better,stronger,faster");
.Javascript.^
MT
一〈/script>.
.1.:Javascript.
3T
.4:JavaScript
.5?:.
.4JavaScript
.Thau!
,<script>JITMLJavaScript.
?//putupanalertbox,toshowhowtheyworkalert("Soon,Iwilloverthrowmy
browser!");
第2章Congratulations
..HTML.
?<html>
<head>
<title>blahblahblah</title>
<scriptlanguage="JavaScript">
<!--hidethisstufffromotherbrowsers
.1.:Javascript.
?-?
3.:.
.JavaScript
5:.
.5.:.
.Thau!
JavaScript.
??
?JavaScript.
?JavaScript.
?JavaScript-
?4)
?JavaScript.
JavaScript
II
???
JavaScript
?JavaScript.
?JavaScript-
?JavaScript.
Page1:Javascript.
Page2:.
Page3:-
Page4:.JavaScript
Page5:.
JavaScript2
.Thau!
JavaScriptJavaScript一
.1T
2.::
3y
.4.:.
.5.:.
.6.:if-then.
.7.:if-then?
.8.:if-then.
.9.:.
.10.:r
.11.:._2_
.12.:.
.Thau!
-JavaScript-
“x=2「x2y=x+3J“y:5
-JavaScript.
<scriptlanguage二〃JavaScript”》
<!-hideme
-JavaScript.
//loadupsomevariables
varsecs_per_min=60;
varmins_per_hour=60;
varhours_per_day=24;
vardays_per_year=365;
..var,
A/ar_
.Somonkey23.
JavaScript
?Loop.loop.
.secsPerMin.
.x,y,.hackhackhack.
?
JavaScript-
JavaScript.
■
Webmonkey-
//dosomecalculations
varsecs_per_day=secs_per_min*mins_per_hour*hours_per_day;
varsecs_per_year=secs_per_day*days_per_year;
-JavaScript.
.secs_per_irear.
.60,60,24,.365-變量
secs_per_year.
//endhiding—>
</script>
JavaScript.
JavaScriptJavaScript
.lr
2.:「
3?
.4.:.
5.:.
.6.:if-【hen.
.7.:if-then.
8:if-then.
9:?
.10.:.
.11.:,_2
.12.::
.3.:-
.Thau!
<scriptlanguageiJavaScript〃>
<!-hideme
JavaScript.
//here,showtouseJavaScripttowriteoutHTML
document,writeln(,,<b>Themonkeydances〃);
document,writein(secs_per_5^ear);
document,writein(,zsecondsperyear.</b><p>/,);
■
document.writeln()-
.document,writein().
?〈script〉.
</script>jdocument.writeln
(〃blah!〃)JHTML
.secs_per_year.
JavaScript-
.secs_peryear
JavaScript
JavaScript
,
document.writeln(''secsperyear/^,JavaScript
.secsperyear_31,536,000.
.document,writeln().HTML.
.<b>.</b>..
-JavaScript
4secs_per_min).
.secs_per_minJavaScript.
.document,writein(secs_per_min).
JavaScript.
2::
3一
.4.:.
.5.:.
.6.:if-then.
.7.:if?then.
.8.:if-then.
.9.:.
.10.:r
.11.:._2_
.12.:r
.4..
.Thau!
varnice_monkey="ThemonkeysmilesatyouandrecitesShakespeare.
varbad_monkcy="Themonkeyscowlsatyouandburps.";
document,writein(nicemonkey);
varmonkey=prompt;/,What,sthemonkey,sname?","Themonkey");
_OK_
-What'sthemonkey's
name?.J'Themonkey".
〃〃\
varmonkey=prompt:〃What'sthemonkey*sname?”,);
vartechy_monkey=nonkey+demanding+tech;
=techymonkey
"Themonkey"+"demands,no,insistsuponreceiving"+"acomputerthat
won'tcrash,andahomemadebrowser!"
vartcchy_monkcy=nonkey+demanding+tech;
vartechy_monkey="Themonkeydemands,no,insistsuponreceivinga
computer
thatwon'tcrash,andahomemadebrowser!”;
varitalic_hippy=hippy_monkey.italics();
varshouting_hippy=hippymonkey.tolipperCase();
varred_bold_tech=bold_tech.fontcolor(*red,);
varitalic_hippy="<i>〃+hippy_monkey+
JavaScript.document,writein
(italic_hippy).
-HTMLJiippy_monkey.
.string,fontcolornewcolor,);-
varredboldtech="〈fontcolor='red'>〃+boldtech+〃〈/font>〃;
varred_bold_tech=bold_tech.fontcolor(*red,);
document,writeln(bo'dtech+〃<br>〃);
varbrokenbold=boldtech+”<br>〃;
document,writein(brokenbold);
.1.
2:「
.4.:.
5.:.
.6.:if-then.
.7.:if-【hen.
8:if-then.
5.:.
.10.:.
.11.:
.12.:,
.5.:.
.Thau!
.HTML.<body>and</body>.mad-lib.
if-then-.
.1?
2:,
3y
.4.:.
.5.:.
.6.:if-then.
.7.:if-then.
.8.:if-then.
.9.:.
.10.:r
.11.:._2_
.12.:r
6.:if-then.
Thau!
"if-then"_
if(someconditionistrue)
(
dosomething;
dosomething;
dosomething;
}
?."if",(if
-if-then-
.if-then.
.1T
2二
3y
.4.:.
.5.:.
.6.:if-then.
.7.:if-then.
.8.:if-then.
.9.:.
.10.:r
.11.:/
.12.二
.7.:?if-then.
.Thau!
.yes.
varmonkey_love=prompt("Doyoulovethemonkey?","Typeyesorno〃);
if(monkey_love二二"yes")
alert(z,Welcome!I'msogladyoucame!Please,readon!”);
jnonkeylove一
jnonkeylove."yes".
JavaScriptjnonkey_love,"yes".
(variable_l>variable_2)istrueifvariable」isgreaterthan
variable2
(variable_l<variable_2)istrueifvariable_lislessthan
variable2
(variable2<=variable2)istrueifvariable1islessthanorequal
tovariable_2
(variable_l!=variable_2)istrueifvariable」docsnotequal
variable_2
if((variable1>18)&&(variable1<21))
(
document,writein(^variable_lcanvote,butcantdrink.");
)
-&&JavaScript-
_&&
if((variable_l=="bananas")||(variable」二二"JavaScript"))
(
document,writein(^Themonkeyishappybecauseithas〃+
variable_l);
)
jf-then.!
2:.r
3、
.4.:.
?5.:.
.6.:if-then.
.7.:if-then、
8:if-then.
.9.:.
.10.:.
.11.:.2
.12.:r
.8.:if-thenExercise
.Thau!
3y
.4.:.
.5.:.
.6.:if-then.
.7.:if-then-
.8.:if-then.
.9.:.
10.:.
.11.:._2
.12.二
.9.:.
.Thau!
JavaScript-
onClick,_onMouseOver.
.<script>_
.onClick.onMouseOver.
JavaScripts-
JavaScripts-
JavaScripts.onClick.
<ahref=〃#〃onClick="alert('Ooo,doitagain!J);z,>Clickonme!</a>
-onClick;〃〃
-JavaScripts.
?alert.
href=〃〃_
<ahref=〃#〃onMouseOver=zzalertCHeehee!');〃>Mouseoverme!</a>
.onMouscOvcr.onClick.
.1T
2:r
.4.:.
5.:.
.6.:if-then.
.7.:if-then.
8:if-then.
?9.::
10.:r
.11.:二
.12.:r
.10.:..
.Thau!
OneofthemostcommonlyusedfeaturesofJavaScriptistheabilitytochangeimages
onamouseover.Unfortunately,MicrosoftInternetExplorer3.0doesnotsupportimage
replacement.Soifyou'reusingIE3.0,itmightbetimetoupgradetoIE4.0orswitchto
Netscape.
JavaScripts
-IE3.0
-正4.0.
Netscape3.0.
Let'sgothroughtheexamplestepbystep.
Thefirstlineofinterestis
<imgsrc="button_r.gif"name="the_image">
Thisisjustlikeastandardexceptthisonehasbeengivenaname:Thisnamecouldbe
anything:myimage,abox,whatever-butitcan'thaveanyspacesinit.
.<imgsrc=>.
.the_image..
*my_image,a_box,一
Thenextlineofinterestis
<ahref="#"
onMouseOver="document.the_image.src='button_d.gif';">change</a>
Thisiswheretheimageswaphappens.It'sjustliketheousawbefore.Theactivepiece
ofJavaScript,whichappearsinthequotesoftheisthis:
onMouseOver.onMouseOver.
JavaScript.
document.thejmage.src='button_d.gif';
Thisstatementsays,"findtheimagecalledandchangeitstoNotethattherearedouble
quotesaroundthewholestatement,andtakessinglequotes.Althoughquotesare
interchangable,ifyouhaveonesetofquotesinsideanothersetofquotes,thesetshaveto
beofdifferentkinds.SoyoucouldeitherdobutnotGotit?
..'lhe_image'.src.
button_d.gif.",
竺utton_d.gif'一
7'something'".'"something"'.
'something"'or""something"
Justastherewasalotofdetailinwhatmakesdocument,writein()work,I'mnot
tellingyouexactlyhowthisimageswapisworking.You'lllearnthedetailsofbothwhenwe
lookatobject-orientedprogrammingandtheDocumentObjectModelinthenextlesson.
.document,writein().
Animportantcaveataboutimageswappingisthattheimageyou'reswitchingtoshould
bethesamesizeastheoriginal.Ifit'snot,it'llgetsmashedorstretchedtofittheoriginal's
size.
.1?
2:「
.4.:.
5.:.
.6.:if-:hen.
.7.:if-then-
8:if-then.
S.:?
.10.:.
.11.:._2
.12.:r
.11.:2
.Thau!
3.1
.i?
2:,
.4.:.
5:.
.6.:if-【hen.
.7.:if-then.
B.:if-then.
.9.:.
.10.:.
.11.:/
.12.:.
.12.:.
.Thau!
LK.
document.writeln()
.document,writein().
.HTML
prompt
.prompt_
if-then-else
.if-then-else.
JavaScript.
.href.onClick.
onMouseOver.
JavaScript..
-JavaScript
JavaScript.
.frames,.
2.::
3y
.4.:.
.5.:.
.6.:if-then.
.7.:if-then.
.8.:if-then.
.9.:
.10.
.11..2
.12.
.5.:.
.Thau!
Ljavascript..HTML.〈body>and</body>.mad-lib.
ThauJavaScript.FiLif-then...
乙
ThauJavaScript「
.lr
2.:.
ThauJavaScript.
3y
.4.:.
…JavaScript--
.5.:.
.6.:if-then.
ThauJavaScript.
.7.:if-then-
.8.:if-then.
ThauJavaScript..9.:.
.10.:P
.11.:._2
.12.::
JavaScript.3.
.Thau!
?JavaScript.HTML.
?.JavaScript.HTML
?JavaScript,if-then.
_window,document.monkey_image.src=〃happy_monkey.gif^Jiappyjnonkey.gif
.monkeyimage._window,document.?.src.?
.document,writein(^,monkey,,).
.document,writein.writeIn?
-(JavaScriptDocumentObjectModeLDOM).DOM.JavaScriptJavaScript
二.DOM.
JavaScript-
?DOMcJavaScript-
.L:
3、
.4;JavaScript.
.5:Windows.
.6^JavaScript-
.7;?
.8::
.9:JavaScriptDOM
.10.:r
.11.:.Window.Frame.
.12,
.13.:r
.2.:..
.Thau!
JavaScript-HTMI_一.href
HTML
clickingon<a
href=z,yer_ncw_window.html〃target=//ycr_new_window,/>this
link</a>willopenanotherwindow.
-"yer_new_window'L"yer_new_window".herf_URI___HTML.
_yer_new_window.
-href.,JavaScript-
?16
2G
3::
.4;J:avaScript.
5JWindows.
.6.::JavaScript.
.7.:
8:
9.:JavaScriptDOM
.10.
.11.:.Window.Frame.
.12.:r
.13^.
.3JavaScript.
.Thau!
.HTMI____JavaScript-
window,open("URL”,〃name〃,“features");
-URL.URL
"http:"/webmonkey/".
-URL.open.
.features—
JavaScript.
.l.T
2k
.4;JavaScript-
.5:Windows.
.6^JavaScript.
.8::
.9:JavaScriptDOM
.10.:r
.11.:.Window.Frame.
.12.:r
.13.:r
.4.:.Jav_
.Thau!
.javascript_l..
.javascript_2..
.javascript_l.HTML..
<ahref二〃#〃
onClick二〃window,open(Jjavascript_window_l.htmT,'javascript」');〃〉Here's
awindownamedjavascriptl</a>.
.javascript_l,javascript_window_l.html.features_
.onClick-window,openO.onClick-<script>.windoivs.open().
-HTML.
<ahref=〃#〃
onClick二〃window,openCjavascriptwindow2.hlml','javascript2'):〃〉Here's
awindownamedjavascript_2</a>.
-HTMI___javascript.l.
<ahref="#〃
,,,
onClick二〃window.open('javascript_window_3.html','javascript」'):>lleres
anotherHTMLpagegoingintojavascript_l</a>.
-features.
OK.windowsfeatures」
.1.L
3.:—
.4.:JavaScript.
±>.:Windows.
.6.:JavaScript^
J;..
8:.
.9.:JavaScriptDOM
.10.:?
.11.:.WindowTrame.
.12^:
.13?:.
.5.
.Thau!
window.open()
window,open(,zsome_url,z,,,window_namez,,^location,menubar");
.URI—
window,open("someurl","windowname","location,height=100,width=100〃);
-100-
menubar.
status.
—URI■一marquee—
scrollbars.
resizable.
width.
height
toolbar.
Homebuttonamongothers.
-HOME.
location.
.URL-
directories.
.Netscape."What'snew,""What'scool,'I
.1.;
3::
.4.:J:avaScript.
Windows.
.6.:.JavaScript-
.7.:
8:
9:JavaScriptDOM
.10:2
.11.:.Window.Frame.
.12.:r
.13.:s
.6JavaScript.(OOM.
.Thau!
-JavaScript-DOM
■,
.-JavaScript.--JavaScript-JavaScript-Window.
-URL.
JavaScript_window—
varthe_status=window,status;
.window.status.the_status-status__
window,status='口monkeyingaround!”;
2T
.4:JavaScript.
.5zWindows.
.6:JavaScript-
.8;,
.9zJavaScriptDOM
.10.
.11..Window.Frame.
.12.
.13.
.7.:.
.Thau!
錯誤!超級鏈接引用無效。
錯誤!超級鏈接引用無效。
<ahref=〃#〃onMouseOver=〃window.status='Monkeys!';〃>Whodowelove?</a>
____window.open("URL,""name1""features")JavascriptJDpen-
varitalic_hippy=hippy_monke)\italics();
.italics3
_alert.prompt_
window,alert(^Vivalaprimate!z,);
-Vivalaprimate!-
錯誤!超級鏈接引用無效…
Itseemssortofsillytojustblurthewindowthatyou'relookingat.Inordertousefocusandblur
moreusefully,youneedtoknowhowtoinvokemethodcallsonotherwindows.
.1J
3.:=
.4.:JavaScript.
5.:Windows.
.6.:JavaScript.
.7二:
?8;.
9:JavaScriptDOM
.10.:.
.11.:.Window.Frame.
.12.:T
.131-
.8.:.
.Thau!
-javascript.
varnewwindow=
window.open(z/hello.htmK,//html_name,/,z,width=200,height=200,z);
rnewwindow.
new_window?
.newwindow..
.newwindowj
ncwwindow.blur();
.window,blur().
<ahref=〃#〃onMouseOver="newwindow,focus0;,?>Bringitforward</a>
<ahref=〃#〃onMouseOver=,/newwindow,blur():,z>Putitbackward</a>
.L,
2T
.4;JavaScript.
.5.:Windows.
.6;JavaScript-
.71
.8;,
.9zJavaScriptDOM
.10.:r
.11.:.Window.Frame.
.12.:,
.13.
.Thau!
JavaScript.
documcnt.HTML.
documcnt-image
swap)-
<ahref=,,#,/
J,,
onMouseOver二〃window,document,theimage,src='buttond.gif;>change</a>
-window.document.
the_image3rc-button_d.gif.
.windows.
.documents?document
jmages.
-JavaScript.
.DocumentObjectModeL
.1G
3.:-
.4.:JavaScript.
S:Windows.
.6.:JavaScript.
.7.:.
18?:.
9:JavaScriptDOM
.10;「
.11.:.Window.Frame.
.12.:r
.13z:
.10.:-
.Thau!
?"FramesAreaPicnic.".
JavaScript-
-javascript-
^avascript-
<framesetrows=〃
<framcsrc=,,frames_example_controls.html〃name=/zcontrol_framc,,>
<framesrc="blank.html〃name=/ztarget_frame/,>
</frameset>
?control_frame,.
.javascript.HTML-
src=#-
.control_frame-
<ahref="#〃
onClick="top.target_frame.document.writeInMonkeydo!<br>,);”>Monkey
see</a>
JavaScript-
-larget_frame.
.documentJavaScript.document.
.uriteln()j'Monkey
do!".writeln().documenL
.document.writelnO.writelnO..
?1G
2.
3
.4.JavaScript.
5Windows.
.6.JavaScript-
.7.
8
9JavaScriptDOM
.10二?
.11.:.Window.Frame.
.12.:T
.131-
.11.:-
.Thau!
-top.
-top.
parent.
-2-parent.
=,.javascript.
.1.,
2,
.4zJavaScript-
.5:Windows^
.6;JavaScript-
.71
.8;:
.9:JavaScriptDOM
.10.:.
.11.:.Window.Frame.
.12:
.13.:,
.12.:.
.Thau!
-2.
.document-bgcolor.HTML
.body-document-
.”「ed,“.16.〃#FF0000〃
JavaScript^
.1.L
2..
.4:JavaScript-
.5?:Windows.
.6:JavaScript,
?7”
.8J.
.9;JavaScriptDOM
.10.:r
.11.Window.Frame.
.12.:,
.13.:T
.13.:.
.Thau!
.DocumentObjectModeL
JavaScript.
.DomainObjectModel)
-DOM.
-HTML.
ZU
2T
.4zJavaScript.
.5:Windows.
.6zJavaScript^
.7;」
.8;:
.9:JavaScriptDOM
.10.:.
.11.:.Window.Frame.
.12.:,
.13.:.
Javascript.:.
.Thau!
Javascript_2Jf-then_Javascript-
Javascript一
Page1:.
Page2:.
Page3:.
Page4:.WHILE.
Page5:-
Page6:.
Page7:.
Page8:.
Page9:.
Page10?
Page11:.
Page12:.
Page13:.
Page14:-
.Thau!
varthe_password="passthewrench";
varanswer=prompt(,,What'sthewoyd?"/'");
if(answer!=the_password){
answer=prompt("Whafsthewoyd?"/'");
if(password!=the_password){
document.write("Youlose!<p>");
}else{
document.write("That'sright!vp>“);
}
}else{
document.write("That'sright!<p>");
}
__if-then_
-(loop)—while.passthewrench.
.1.:.
.4;.WHILE.
.5:For.
.6;.
.8;:
.9::
g
.12.:r
.13.:?
.14.:.
.Thau!
Javascript_
varpassword="passthewrench";
varanswer;
-answer-answer.
while(answer>=password)
{
answer=prompt("What'sthewoyd?","");
)
.while.while-
while(sometestistrue)
{
dothestuffinsidethecurlybraces
)
..answer.Password—(Passthewrench).
_(answeri=password)_answer.while.answer.answer_.
.1.:-
.4:.WHILE.
.5:For.
.6二.
.7-
.9z.
g
.11.:?
.12.”
.13.:r
.14.:.
.4.WhileLoops
.Thau!
XS.
xs.
varwidth=prompt(^Howmanyx'swouldyoulike?(1-10isgood)”,"5");
vara_line="〃;
varloop=0;
a
whi1e(loop<width)
(
a_line=a_line+"x";
loop=loop+l;
!
.3.
alert(a_line);
while(loop<width)
(
aline+=〃x〃;//thiswasaline=aline+〃x
loop++;//thiswasloop=loop+l;
)
..x..x-a_number=5.a_number+=3.a_number=a_number+3..
」oop++..l」oop++.loop=loop=Lloop+=l-
-1-While-forloop
.1^.
2::
3,:-
.4.:.WHILE.
5:For.
.6;?
.7;:
8:,
.9.:,
.10
.11.::
.12.::
.13^r
.14.:.
Jhau!
.while.
1?〃〃
vara_lme=;
varloop=0;
while(loop<width)
(
a_line=aline+"x
loop=loop+l:
}
.ForLoop.
varalinc=
for(loop=0;loop<width;loop++)
a_line=a_line+"x”;
I
for.
for(initialvalue;test;increment)
dothisstuff;
)
.forloop」oop二O.Uoopvwidthwhileloop-.ajine.widthx.
.1.:.
.4..WIIILC.
.5JFor.
.6;.
.8;.
.9;:
g
.11.:,
.12.:r
.13.:r
.14.:r
.Thau!
varheight=promptJ^Howhighdoyou
wantthegrid?(1-10isgood)〃,〃10〃);
varwidth=prompt(''Howwidedoyouwant
thegrid?(l_10isgood)〃,"10");
vara_line;
varnewwindow=
window,open(',/webmonkey/98/04/filesla
/grid.“l(fā)ooper",〃width=400,height=400");
npwwindow.documpnt.writ.pln(/z<hI>AGrid</h'>,z):
for(height_loop=0;height_loop
<height;height_loop++)
1?〃//
a_line=;
for(widthloop=0;
widthJoop<width;widthloop++)
a_liae+=〃x〃;
newwindow.docuinenL.wriLein
(a_line+〃<br>〃);
_for_for?a」ine二..一ajine-for_X'S_height.
.1:.
2;.
A:.WHILE.
5.:For.
.6.:.
?7;?
.103
.11.:f
.12.:.
13zr
.14:二
.7.
.Thau!
.1:.
."WHILE.
.5:For.
.6;.
.7,:
.8;.
.9::
g
.n.:,
.12.:r
.13;?
.14.:T
.Thau!
Javascript.
-URL.
varcolors=newArray("red","blue","green");
XL
varthe_element=colors[0];
JavaScript.theelement
."red".
Z2.1,
2.
colorsfO]="purple";
.1.:.
.3::
"WHILE.
.5;For.
.7::
.8一
g
.11.:r
.12.:r
.13.:r
.14.:.
.9.
.Thau!
LRL,
varurl_names=newArray("〃,“awaken.org〃,“bianca.com");
vara_url;
.URLalert.OK.
for(loop=0;loop<url_names.length;loop++){//makethenameofaurl,f
/a_url="http://www."+url_naines[loop]+7";//openawin(
ncw_window=opcn(a_url,"ncw_window","width=300,hcight=300");//waitforthe
nextsite");}
.0.
urlnamcs.length.,length.
.array[2].J..
.array[0]..
2objectnotfound"-
二length.
」ength-
?urlnames二new
Array().
.url_names.
."new"-
aurl=〃http:〃www.〃+urlnames[loop]+〃/〃;
.Qurl_namcs.
.l/hits.org〃.
上url/http:
//www.hits.org/〃.
.URL.
varnewwindow=open(aurl,/znewwindow^,,,width=300,height=300,z);
JJRL.
//newwindow”.
.3alert:-
.OK.
JavaScriptDocument
ObjectModeL
,1:,
3:,
4:.WHILE.
5:For.
.6;.
3,:.
?9?:.
.10.L
.11::
.12;r
.13.:.
.14.:T
.10-(DOM)
.Thau!
-DOMJE3.0.Netscape2.0-
Here'stheJavaScriptthat'sintheonClick=〃〃inthelink:
varchange=prompt(JChangewhichimage(0or1)?','');
window,document,images[change].src=,three,jpg';
-DOMJE3.0.Netscape2.0-
document.image_name.src='some_image.gif';
-HTML-DOM.
.1ITML-document.images[0]-clocument.images[l]—document.imageslength-
SpacerGLF_
for(loop=0;loop<document,images,length;loop++)
(
document,imagesLloopJ.src='spacer,gif';
}
.1.:.
3T
.4;.WHILE.
.5:For.
.6?:.
.8::
.9;:
.10
.12.:r
.13.:r
.14.:r
第十一頁:函數
函數是編程需學的最后一個基本組成。所有的程序語言都是
函數。函數是一些角次可調用的、無須重寫的東西。
如果你想教會自己快速閱讀并且用一個一旦點擊可告訴你當前
時間的長文本鏈接。
例如…時間!
看源碼:
<ahref="#"onClick="
varthe_date=newDate();
varthe_hour=the_date.getHours();
varthe_minute=the_date.getMinutes();
varthe_second=the_date.getSeconds();
varthe_time=the_hour++the_minute++the_second;
alert('Thetimeisnow:1+the_time);">time!</a>
在這里這段JavaScript的工作細節(jié)并不重要;一會我們再回來
復習一下。
重要的是它太長了。若這些時間鏈接再有10個,你須每次剪貼
這段程序。這使你的HTML既長且難看。另外,若你想改變這段
程序,就必須在10個不同地方改變。
你可以寫一個函數來執(zhí)行而不用作10次拷貝程序。這里的函數
使用變的即容易編輯又容易閱讀。
請看如何寫一段計時函數。
Page12:.
.Thau!
.HTML-announceTime_
annoumnceTime
<ahref="#〃onClick=,,announceTime();z/>time:</a>
<ahref="#〃onClick="alert('Hello!');">Hel:o!</a>
JHTML.
<html>
<head>
<title>FunctionwithNoParameters</1itle>
<scriptlangauge=/,JavaScript'^
<!-hideme
functionannounce?ine()
(
//getthedate,thehour,minutes,andseconds
varthe_date=newDate();
varthe_hour=the_date.getHours();
varthe_minute=the_date.gctMinutesO;
varthesecond=the_date.getSeconds0;
//puttogetherthestringandalertwithit
varthe_time=the_hour+〃:〃+the_minute+":〃+the_second;
alertC'Thetimeisnow:〃+the_tinie);
}
//showme—>
</script>
</head>
<body>
</body>
</html>
functionfunctionNane(parameterlist)
(
statements
)
varthedate=newDateO;
varthehour=thedate.getHours0;
vartheminute=thedate.getMinutes();
varthesecond=the.date.getSecondsO;
JavascriptJavascript
-12:12:04.
.getSecond()-4.-
』he_minute+.:.+the_second.14:4
■
?1:r
2:,
3.:.
.4.:.WHILE.
5:For.
.9.:,
.10.L
.11.::
.12z:
.13J:
.14.:T
.13.:.
.Thau!
-HTML.
_10-
.04.4.
varthejninute=the_date.getMinutesO;
if(the_minute<10}
(
the_minute=〃0〃+the_minute;
)
varthesecond=thedate.getSeconds();
if(the_second<10)
(
the_second=〃0"+the_second;
}
J.CLO.
fixNumber.
functionfixNumbcr(the_numbcr)
(
if(the_number<10)
(
the_number="0〃+the_number;
}
returnthe_number;
}
fixNumber.thenumber..
varfixed_variable=fixNumber(4);
.the_number-4-
.fixNumber_
.thenumber.10.
.OJ"eturn.
thenumber-return
varsome_variable=someFunction();
.somevariable.函數someFunction().
.fixNumber.return
£he_number.the_number.
varfixedvariable=fixNumber(4);
the_number_4
.4.1Q.the_number."04"..
.the_number.
fixedvariable."04"..
.fixNumberjinnounceTime()
functionannounceTime0
//getthedate,thehour,minutes,andseconds
varthe_date=newDate0:
varthe_hour=the_date.getHoursO;
varthe_minute=the_date.getMinutesO;
varfixedminute=fixNumber(theminute);
varthesecond=thedate.getSeconds();
varfixedsecond=fixNumber(thesecond);
//puttogetherthestringandalertwithit
varthe_time=the_hour+”:〃+fixedminute+〃:〃+fixedsecond;
alert(z,Thetimeisnow:〃+the_time);
}
-12:04:05.new
Date().getHours().
-4,?
.fixNumber.theminute:
varfixed_minute=fixNumber(the_minute);
.fixNumber().the_number.
.the_minute.the_minute.4
.thenumber.4.
-4.10the_number.
."04".the_nuinber.return_
"04".fixNumber.fixed_minute.
."04"..
12:04:05.
.^nnounceTime0.
1.the_minute=the_date.getMinutesO;
.thc_minute=4
2.fixed_minute=fixNumber(the_minute);
.函數fixNumber().
fixedminute
3.5.fixNumberO
3..fixNumber(the_number)
fixNumbcr().the_minute.
the_minute.4thenumber=4
4./the.number<10){the_number="0"
+the_number;}
.4.1Q.the_number."04"
5..the_number.
."04"
3.6.fixTime().
^nnounceTime()
6.."04".fixed_minute.
."04"
.1;.
2.::
3.:.
A.:.WHILE.
5.:For.
.6.:.
.7.:r
?91:
.10&
.11.::
.12.:,
.131:
.14二.
.14.:.
.Thau!
varmonkeys=newArray("mattmarg","wendy","kristin”,〃tim〃,“aaron”,〃luke〃);
varkittyphile=newArray(〃wendy〃,“ruby〃,〃roscoe〃,〃tim〃);
vardiscophile=newArray(^mattmarg^,〃johntravoltaz,,〃wendy〃);
varhappy=newArray(〃tim〃,“wendy","stinpy”,〃aaron〃);
varcranky=newArray(〃rcn〃,〃mattmarg〃,〃:uke〃);
-arrayIntersect—
JohnTravolta-monkeys-
<ahref=〃#〃onClick=,,arraylntersectdancingrnonkeys,,monkeys,discophile);,z>dancingi
<ahref=〃#〃onClick=/,arraylntersect(Jmonkeyswholovecats,,monkeys,kittyphile);z,>ca
^rraylntersect.
functionarrayIntersect(intersectname,array1,array2)
(
varthe_list=〃”;
for(loop_l=0;
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 考試題解析質量數據分析應用案例分析
- 深度解析(2026)《GBT 19275-2003材料在特定微生物作用下潛在生物分解和崩解能力的評價》
- 風險管理與內部控制考試題庫
- 通信行業(yè)人力資源部工作手冊及面試題集
- 獨居老人術后焦慮抑郁干預方案
- 深度解析(2026)《GBT 18758-2002防偽核技術產品通 用技術條件》(2026年)深度解析
- 軟件測試崗位招聘面試技巧全解
- 深度解析(2026)《GBT 18916.27-2017取水定額 第27部分:尿素》
- 圓刻線機項目可行性分析報告范文
- 深度解析(2026)《GBT 18769-2003大宗商品電子交易規(guī)范》
- 物業(yè)有限空間作業(yè)管理制度
- 2024學年安徽省江南十校高一上學期12月聯考物理試題及答案
- 六章 幾何圖形初步 專題一-線段的計算 教學設計 2024--2025學年人教版數學七年級上冊
- 2GW高效N型Topcon電池智能制造項目可行性研究報告模板-立項拿地
- 鄉(xiāng)村振興戰(zhàn)略的理論與實踐智慧樹知到期末考試答案章節(jié)答案2024年華中師范大學
- 金屬硬度轉換表【HLD,HRC,HRB,HV,HB,HSD】
- 建材有限公司砂石卸車作業(yè)安全風險分級管控清單
- 中石化華北分公司鉆井定額使用說明
- 礦山壓力與巖層控制智慧樹知到答案章節(jié)測試2023年湖南科技大學
- 機加工車間主任年終總結3篇
- WB/T 1119-2022數字化倉庫評估規(guī)范
評論
0/150
提交評論