WEB_网页编程技术_第4章 JavaScript.pdf
?E-mail:pengliscfc.edu?4?JavaScript?4.1 JavaScript?4.2 JavaScript?4.3 JavaScript?4.4 JavaScript?4?JavaScript?4.1 JavaScript?Netscape?Web?LiveScript?Sun?Java?JavaScript?Livescript?JavaScript?HTML?JavaScript?Internet Explorer?Mozilla?Firefox?Netscape?Opera?4?JavaScript?4.1.1 JavaScript?1?JavaScript?2?JavaScript?3?JavaScript?4?JavaScript?(event-driven)?5?JavaScript?Event?Event Driver?4.1.2 JavaScript?JavaScript?HTML?JavaScript?HTML?JavaScript?JavaScript?HTML?JavaScript?JavaScript?JavaScript?cookies?4?JavaScript?4.1.3 JavaScript?1?JavaScript?Java 2?JavaScript?VBScript 3.javaScript?Jscript?4?JavaScript?4.1.3 JavaScript?1?Javascript?java?javascript?java?Java?JavaScript?Java?C?C+?4?JavaScript?4.1.3 JavaScript?3?Javascript?Jscript?web?html,?netscape?Navigator?LiveScript?JavaScript,Microsoft?jscript?internet explorer explorer?jscript?javascript?web?ECMAScript,?javascript?LANGUAGE=JavaScript?HTML?4.2 JavaScript?3?1?2?_?$?3?4?JavaScript?4.2 JavaScript?4.2.3?:+,-,*,/,%,+,-,-(?:&,|,!?:=?=?,=,1&54?true 21&51|51|54,?true?3?true?false,?false?true?(21)?false?4.2 JavaScript?3.?:=?=?=?,=,=?x=“5”?true 4.2 JavaScript?4.?:=?+=?-=?*=?/=?%=?1?+=”?X=5?Y=5?X+=Y?10?X?2?-=”?X=5?Y=5?X-=Y?0?X?3?*=”?X=5?Y=5?X*=Y?25?X?4?/=”?X=5?Y=5?X/=Y?1?X?5?%=”?X=25?Y=7?X%=Y?4?X?4.2 JavaScript?5.?1?1?2?2?true?1?false?2?day=“?4.2 JavaScript?6.?+?+”?太abc+“?abc?4.2 JavaScript?7.?1?*?/?%?2?+?-?3?=?=?=?!=?=)?4?&)?5?事事)?6?(?:)?(4*5+1822)?”?:”?4.2 JavaScript?8.?4.2 JavaScript?4.2.4?2?if-else?1?if(?)?2;?4.2 JavaScript?3?switch?4.2 JavaScript?2?1?for?4.2 JavaScript?2?while?while(?)?for(var i=1;i=3;i+)document.write(“”);?document.write(i+”.”+prompt(?末+i?太?末);?3?do-while?while?dowhile?do?;?;while(?)?4?break?continue?break break?Continue continue?The number is 0 The number is 1 4.2 JavaScript?3?(?for(variable in object|array)statements?1?for-in?with?variable:?object?array?for(?in?)?object,array:?Math?function=Math.cos(3*Math.PI)+Math.sin(Math.LN10)ForInDemo()x/?2?with?Math.E)y=Math.tan(14*var a,key,s=;/?with(?)a=“a”:“Athens”,“b”:“Belgrade”,“c”:“Cairo”/?a.a,a.b,a.c?with?/?with(Math)for(key in a)x=cos(3*PI)+?3?return?s+=akey+ sin(LN10)/s+=key+“ ”;/?a b c”?s?y=tan(14*E)?/?/*?*/?4?return(s);?4.2 JavaScript?4.2.4?JavaScript?1?function?(?1,?2)?2?3?return?4.?4.2.5?JavaScript?name=Hege“name=Hege?document.write(Hello World!)?document.write (Hello World!)?”b?var txt=“We are the so-called”Vikings“from the north.document.write(txt)JavaScript?We are the so-called Vikings from the north.4.3 JavaScript?JavaScript?Math?String?Date?Time?Array?window?4.3 JavaScript?4.3.1 Math?Math?new?Math.?(?)1?Math?(?P347)2?Math?(?P347)3?Math?:?math.htm 4.3 JavaScript?4.3.2 String?0?JavaScript?太末?String?String?String?4.3 JavaScript?1?String?(?)?str1=hello;?new?:str2=new String(hello);2?String?length(?)3?String?String?4.?1:?2:?3:?-indexof?4:?4.3 JavaScript?4.3.3 Date?JavaScript?Date?1?Date?var?=new Date(?)?,Date?:var myDate=new Date()/?2?Date?4.3 JavaScript?3.?1?Date()?date1.htm?2:?date2.htm?3:?1970?:getTime.html?4:?:setFullYear.html?5:?:clock.html 4.3 JavaScript?4.3.4 Array?JavaScript?Array?1?Array?:?new?var Tips=new Array(6);2.Array?:?:?var mycars=new Array()/?mycars0=Saab mycars1=Volvo mycars2=BMW?var mycars=new Array(3)/?3 mycars0=Saab mycars1=Volvo mycars2=BMW?:?var mycars=new Array(Saab,Volvo,BMW)3.?:?var mycars=new Array(Saab,Volvo,BMW)document.write(mycars0)/?Saab 4.?mycars0=Opel;5?Array?6?Array?7?Array?array.htm?:for-in-?-concat?-join?-sort?-sort()4.3.4 Boolean?Boolean?true?false?new?Boolean?:?var myBoolean=new Boolean()?0?-0?null?false?undefined?NaN?false?true?false?false?Boolean?var myBoolean=new Boolean()var myBoolean=new Boolean(0)var myBoolean=new Boolean(null)var myBoolean=new Boolean()var myBoolean=new Boolean(false)var myBoolean=new Boolean(NaN)?true?Boolean?var myBoolean=new Boolean(true)var myBoolean=new Boolean(true)var myBoolean=new Boolean(false)var myBoolean=new Boolean(Richard)Boolean?Boolean?:Boolean.html?.html(?appVersion?.3.?navigator?JavaScriptparseFloat()?navigator?Navigator?appName?appName?Netscape?Microsoft Internet Explorer?appVersion?4.3 JavaScript?4.3.6?window?4.3.6.1?_self?_blank?window?_parent?_top?window?newwin=open(“confirm.htm”,“?,height=200,width=400,top=200,left=200,toolb ar=no,menubar=no,scrollbar=no,resizeable=no,lo cation=no,status=no);?window?open?window_open()?4.3 JavaScript?4.3.6.2?document?document?P344?1?document1.htm?document?HTML?,?HTML?HTML?document?all,?,?IE?2?HTML?document2.htm 4.3 JavaScript?4.3.6.3?history?history?URL?history.htm 4.3 JavaScript?4.3.6.4?screen?location?screen?window?location?window?URL?:?,?,?800*600?,?Web?screenandlocation.htm 4.3 JavaScript?4.3.6.5?form?form?,?form?.?form?,?form?1?form?form.htm?2?1?2?3?4(?)4.3 JavaScript?4.3.6.6?window?window?1?JavaScript?JavaScript?3?window?3?alert()?confirm()?prompt()?3?alert(?)?window?alert?alert.htm?true?false?confirm(?)?window?confirm?confirm.htm?null?prompt(?,?)?window?prompt?prompt.htm 4.3 JavaScript?2?window?open?close?openandclose.htm 4.3 JavaScript?(3)?window?status?status.htm 4.3 JavaScript?(4)?window?window?setTimeout()?setInterval()?clearTimeout()?clearInterval()?1?1?0?settimerun.htm 4.3 JavaScript?4.3.6?1?escape()?%XX?,?,XX?ASCII?16?var ss=tom&show;?var sa=escape(ss);?%20?URL?./sa?tom%20%26%20show?2?unescape()?3?eval()?4?parseInt()?,?,?NaN?5?parseFloat()?,?,?NaN?6?isNaN()?4.3 JavaScript?ForInDemo()4.3.7?/?1?var a,key,s=;/?=?1:?1,?2:?2,?n:a=a:?nAthens,b:Belgrade,c:Cairo/?2?for(key in a)function?(?1,?2,?n)s+=akey+ this.?1=?1;this.?2=?2;return(s);this.?n=?n;this.?1=?1;this.?2=?2;this.?n=?n;?4.4 JavaScript?JavaScript?blur?click?change?focus?load?unload?mouseover?select?submit?JavaScript?on?blur?onblur,?(?)?onAbort onBlur?Image Button,checkbox,fileupload,frame,p assword,radio,select,text,textarea,w indow Fileupload,radio,select,text,texarea Button,checkbox,document,link Area,checkbox,document,link image Button,checkbox,fileupload,frame,p assword,radio,select,text,textarea,w indow Document,image,link,textarea onChange onClick onDbClick onError onFocus?onKeyDown?(?)?onKeyPress onKeyUp onLoad onMove?Document,image,link,textarea Document,image,link,textarea Document,image frame Button,document,link Area,layer,link Area,layer,link Button,document,link document form onMouseDown?onMouseOut onMouseOver onMouseUp onMouseMove onReset?(?)?onResize onSelect onSubmit onUnload?Frame,window Text,textarea form document 4.4 JavaScript?1?4.4 JavaScript?2?onchange?4.4 JavaScript?5?3?onMouseOver?onMouseOver?4?5?JavaScript?cookie?cookie?cookie?cookie?JavaScript?cookie?cookie?cookie?/?cookie?Welcome John Doe!?cookie?cookie?/?/?cookie?cookie?cookie?cookie?Your last visit was on Tuesday August 11,2005!?cookie?