Professional Documents
Culture Documents
avascript l mt ngn ng thng dch (interpreter), chng trnh ngun ca n c nhng (embedded) hoc tch hp (integated) vo tp tin HTML chun. Khi file c load trong
Browser (c support cho JavaScript), Browser s thng dch cc Script v thc hin cc cng vic xc nh. Chng trnh ngun JavaScript c thng dch trong trang HTML sau khi ton b trang
c load nhng trc khi trang c hin th. Javascript l mt ngn ng c c tnh: n gin. ng (Dynamic). Hng i tng (Object Oriented).
2. Ngn ng JavaScript:
Mt trong nhng c tnh quan trng ca ngn ng JavaScript l kh nng to v s dng cc i
tng (Object). Cc Object ny cho php ngi lp trnh s dng pht trin ng dng. Trong JavaScript ,cc Object c nhn theo 2 kha cnh: a. Cc Object tn ti. b. Cc Object do ngi lp trnh xy dng. Trong cc Object tn ti c chia thnh 2 kiu: a. Cc Object ca JavaScript (JavaScript Built-in Object). b. Cc i tng c cung cp bi mi trng Netscape.
JAVASCRIPT
PAGE: 1
Cung cp cc tnh cht v phng php lm vic vi cc a ch URL hin hnh c m. Cc i tng history cung cp thng tin v cc danh sch c v c th gii hn s tng tc vi danh sch. y l mt i tng c s dng nhiu nht .N cha ng cc i tng,tnh cht v cc phng php lm vic vi cc thnh phn ca ti liu nh cc :form,link,anchor,applet.
trnh vi nhin liu c: Airplane.description() Airplane.distance() c. To mt instance ca i tng: Trc khi thao tc vi mt i tng ca JavaScript ta phi to mt instance cho i tng .
n cc Scripts i
JAVASCRI P T
PAGE: 2
Bi 2: S DNG JAVASCRIPT
1. C php c bn ca lnh :
JavaScript xy dng cc hm,cc pht biu,cc ton t v cc biu thc trn cng mt dng v kt thc bng ; V d: document.writeln("It work<BR>");
2.
Cc khi lnh:
Nhiu dng lnh c th c lin kt vi nhau v c bao bi { } V d: { document.writeln("Does It work"); document.writeln("It work!");
}
JAVASCRIPT
PAGE: 3
V d 1:
<HTML> <HEAD> <TITLE>Outputting Text</TITLE> </HEAD> <BODY> This is text plain <BR> <B> <SCRIPT LANGUAGE="Javascript"> <!- document.write("This is text bold - -> </SCRIPT> </BODY> </HTML> </B>");
V d 2:
<HTML> <HEAD> <TITLE>Example 2.4 </TITLE> </HEAD> <BODY>
<SCRIPT LANGUAGE="Javascript">
<!- -
5. PRE:
<HTML>
<HEAD>
<!- document.writeln("One,");
PAGE: 4
V d 2:
<HTML> <HEAD> <TITLE>Listing 2.6</TITLE> </HEAD> <BODY>
<SCRIPT LANGUAGE="Javascript">
Cc kiu
document.write("Your favorite color is:"); document.writeln(prompt("enter your favorite color:","Blue")); - -> </SCRIPT> </BODY> </HTML>
document.write("<H1>Greeting ,"); document.writeln(prompt("enter your name:","name")); document.write("Welcome to netscape navigator 2.01 </H1>");
document.write("<H1>Greeting ," prompt("enter your name:","name") Welcome to netscape navigator 2.01 </H1>"); - -> </SCRIPT> </BODY> </HTML>
+ + "
JAVASCRIPT
PAGE: 5
<TITLE>Example 3.1</TITLE> <SCRIPT LANGUAGE="Javascript"> <!- var name=prompt("enter your name:","name"); - -> </SCRIPT> </HEAD>
<BODY> <SCRIPT LANGUAGE="Javascript"> <!-document.write('<IMG SRC="Welcome.gif">'); document.write("<H1>Greeting ," + name + " Welcome to netscape navigator 2.01 </H1>"); --> </SCRIPT> </BODY> </HTML> </HEAD> <BODY> <SCRIPT LANGUAGE="Javascript"> <!-document.write('<IMG SRC="Welcome.gif">'); document.write("<H1>Greeting ," + name + " Welcome to netscape navigator 2.01 </H1>"); --> </SCRIPT> </BODY> </HTML>
V du 2: to li mt gi tr mi cho bin
<HTML> <HEAD> <TITLE>Example 3.2</TITLE> <SCRIPT LANGUAGE="Javascript"> var name=prompt("enter your name:","name"); alert ("greeting " + name + " , "); name=prompt("enter your friend's name:","friend's name"); </SCRIPT>
PAGE: 6
*= Nhn bn tri cho bn phi,gn kt qu cho bn tri x*=y => x=50 /= Chia bn tri cho phi ,gn kt qu li cho bn tri x/=y => x=2 %= Chia bn tri cho bn phi v ly s d gn li cho bn tri x%=y => x=0 * Cc ton t khc: V d: x+=15+3 y=++x; (=> y=6 v x tng ln 6) => x=18 z=x++; (=> z=6 v sau x gn cho z) 8+5 sau x tng 1 => x=7 32.5 * 72.3 Do ta c kt qu cui cng l: 12 % 5 x=7;y=6;z=6; Du ++ v du - - v du V d: x=5; V d: x=-x => x=-5 x=5; Php ton Logic && : v ||: hoc ! not V d: x=5 ,y=2 ,c=3 (x>y) && (x>c) false && anything is always false (x>y) || (c<x) => true !x Ton t so snh trong JavaScript: == 1==1 => true != 3<1 =>false > 5 >=4 =>true < the != he => true >= 4==4 =>true
<=
JAVASCRI
PAGE: 7
(day=Saturday) ? Weekend : Not Saturday Ton t chui: Welcome to + Netscape Navigator V d: Var welcome=Welcome to Welcome += Netscape Navigator
welcome= Welcome to Netsacpe Navigator
<TITLE>Example 3.3</TITLE> <SCRIPT LANGUAGE="Javascript"> var question="What is 10+10 ?"; var answer=20; var correct='<IMG SRC="correct.gif">'; var incorrect='<IMG SRC="incorect.gif">'; var response=prompt(question,"0");
var output = (response==answer) ? correct:incorrect; </SCRIPT> </HEAD> <BODY> <SCRIPT LANGUAGE="Javascript"> <!-document.write(output); --> </SCRIPT> </BODY> </HTML>
12. Cu trc iu kin if else if iu kin lnh ; if iu kin { M JavaScript } V d: if (day==Saturday) { document.writeln(Its the weekend); alert( Its the weekend); } V d: If (day==Saturday) { document.writeln(Its the weekend); } Cu trc kt hp : if iu kin 1 { Cc lnh JavaScript
JAVASCRIPT
If (day!=Saturday) { document.writeln(Its not Saturday); } S dng cu trc else if cho v d trn If (day==Saturday) { document.writeln(Its the weekend); } else { document.writeln(Its not Saturday); }
PAGE: 8
if iu kin 2 { Cc lnh JavaScript } else { cc lnh khc } Cc lnh JavaScript } else { Cc lnh khc } V d 1 : S dng phng php confirm() vi pht biu if
<HTML>
<HEAD>
}
response=prompt(question,"0"); var output = (response ==answer ) ? correct:incorrect ; </SCRIPT> </HEAD> <BODY> <SCRIPT LANGUAGE="Javascript"> <!-document.write(output); --> </SCRIPT> </BODY> </HTML>
<TITLE>Example 3.3</TITLE> <SCRIPT LANGUAGE="Javascript"> var question="What is 10+10 ?"; var answer=20; var correct='<IMG SRC="correct.gif">'; var incorrect='<IMG SRC="incorect.gif">'; var response=prompt(question,"0"); if (response != answer) { if (confirm("Wrong ! press OK for a second change")) <HTML>
<HEAD>
<TITLE>Example 3.3</TITLE> <SCRIPT LANGUAGE="Javascript"> var question="What is 10+10 ?"; var answer=20; var correct='<IMG SRC="correct.gif">'; var incorrect='<IMG SRC="incorect.gif">'; var response=prompt(question,"0"); if (response != answer) { if (confirm("Wrong ! press OK for a second change")) response=prompt(question,"0"); }else { if (confirm("Correct ! press OK for a second question")) {
MTWRFSS
response=prompt(question,"0"); }
}
var output = (response ==answer ) ? correct:incorrect ; </SCRIPT> </HEAD> <BODY> <SCRIPT LANGUAGE="Javascript"> <!-document.write(output); --> </SCRIPT> </BODY> </HTML>
JAVASCRIPT
PAGE: 9
BI 3: HM V I TNG
Trong k thut lp trnh cc lp trnh vin thng s dng hm thc hin mt on chng trnh th hin cho mt module no thc hin mt cng vic no .
Trong Javascript c cc hm c xy dng sn gip bn thc hin mt chc nng no v
d nh hm alert(), document.write(), parseInt() v bn cng c th nh ngha ra cc hm khc ca mnh thc hin mt cng vic no ca bn, nh ngha hm bn theo c php sau: function function_name(parameters, arguments)
{
command block
}
Truyn tham s:
function printName(name) { document.write(<HR>Your Name is <B><I>); document.write(name); document.write(</B></I><HR>);
}
V d:
Gi hm printName()vi lnh sau printName(Bob); Khi hm printName()c thi hnh gi tr ca name l "Bob" nu gi hm printName()vi i s l mt bin
= Mr. + name;
Phm vi ca bin:
Bin ton cc (Global variable) Bin cc b (Local variable)
Tr v cc gi tr:
V d: Dng return tr v gi tr ca bin cube. function cube(number) { var cube = number * number * number; return cube;
MTWRFSS
PAGE: 10
V d:
MTWRFSS
<HTML> <HEAD> <TITLE>Example 4.1</TITLE> <SCRIPT LANGUAGE=JavaScript> <!-- HIDE FROM OTHER BROWSERS //DEFINE FUNCTION testQuestion() function testQuestion(question) { //DEFINE LOCAL VARIABLES FOR THE FUNCTION var answer=eval(question); var output=What is + question + ?; var correct=<IMG SRC=correct.gif>; var incorrect=<IMG SRC=incorrect.gif>; //ASK THE QUESTION var response=prompt(output,0");
// STOP HIDING FROM OTHER BROWSERS -> </SCRIPT> </HEAD< <BODY> <SCRIPT LANGUAGE=JavaScript> <!-- HIDE FROM OTHER BROWSERS //ASK QUESTION AND OUTPUT RESULTS var result=testQuestion(10 + 10); document.write(result); //STOP HIDING FROM OTHER BROWSERS --> </SCRIPT> </BODY> </HTML>
Hm gi li hm:
<HTML>
<HEAD>
V d:
<TITLE>Example 4.2</TITLE> <SCRIPT LANGUAGE=JavaScript> <!-- HIDE FROM OTHER BROWSERS //DEFINE FUNCTION testQuestion() function testQuestion(question) { //DEFINE LOCAL VARIABLES FOR THE FUNCTION var answer=eval(question); var output=What is + question + ?; var correct=<IMG SRC=correct.gif>; var incorrect=<IMG SRC=incorrect.gif>; //ASK THE QUESTION var response=prompt(output,0");
// STOP HIDING FROM OTHER BROWSERS -> </SCRIPT> </HEAD< <BODY> <SCRIPT LANGUAGE=JavaScript> <!-- HIDE FROM OTHER BROWSERS //ASK QUESTION AND OUTPUT RESULTS var result=testQuestion(10 + 10); document.write(result); //STOP HIDING FROM OTHER BROWSERS --> </SCRIPT> </BODY> </HTML> //DEFINE LOCAL VARIABLES FOR THE FUNCTION var answer=eval(question); var output=What is + question + ?; var correct=<IMG SRC=correct.gif>;
JAVASCRIPT
V d 2:
<HTML> <HEAD> <TITLE>Example 4.2</TITLE> <SCRIPT LANGUAGE=JavaScript> <!-- HIDE FROM OTHER BROWSERS //DEFINE FUNCTION testQuestion() function testQuestion(question,chances) {
PAGE: 11
var incorrect=<IMG SRC=incorrect.gif>; 4 //ASK THE QUESTION var response=prompt(output,0"); //CHECK THE RESULT if (chances > 1) { return (response == answer) ? correct : testQuestion(question,chances-1);
} else {
: incorrect;
} }
// STOP HIDING FROM OTHER BROWSERS -> </SCRIPT> </HEAD> <BODY> <SCRIPT LANGUAGE=JavaScript> <!-- HIDE FROM OTHER BROWSERS //ASK QUESTION AND OUTPUT RESULTS var result=testQuestion(10 + 10,3); document.write(result); //STOP HIDING FROM OTHER BROWSERS --> </SCRIPT> </BODY> </HTML>
JAVASCRIP
MEDIASPA
CE CLUB (HTD)
function student(name, age, grade, mother) { this.name = name; this.age = age; this.grade = grade; this.mother = mother;
}
PAGE: 12
bobGrade = new grade(75,80,77); janeGrade = new grade(82,88,75); student1 = new student(Bob,10,bobGrade); student2 = new student(Jane,9,janeGrade); student1.grade.math:dng ly im Ton ca student1 student2.grade.science: dng ly im mn Khoa hc ca student2
function student(name,age, grade) { this.name = name; this.age = age; this.grade = grade; this.mother = mother; this.displayProfile = displayProfile;
}
student1.displayProfile();
V du:
<HTML>
<HEAD>
<TITLE>Example 4.3</TITLE> <SCRIPT LANGUAGE=JavaScript> <!-- HIDE FROM OTHER BROWSERS //DEFINE METHOD
PAGE: 13
Vi du:
document.writeln(Social Security Number: + this.socsec); document.writeln(Annual Salary: + this.salary); document.write(</PRE>);
}
<script LANGUAGE="JavaScript"> <!-- Begin var day=""; var month=""; var ampm=""; var ampmhour=""; var myweekday=""; var year=""; mydate = new Date(); myday = mydate.getDay(); mymonth = mydate.getMonth(); myweekday= mydate.getDate(); weekday= myweekday; myyear= mydate.getYear();
this.displayInfo=displayInfo;
}
newEmployee=new employee();
year = myyear;
// STOP HIDING FROM OTHER BROWSERS -> </SCRIPT> </HEAD> <BODY> <SCRIPT LANGUAGE=JavaScript> <!-- HIDE FROM OTHER BROWSERS newEmployee.displayInfo(); // STOP HIDING FROM OTHER BROWSERS -> </SCRIPT> </BODY> </HTML>
myhours = mydate.getHours(); ampmhour = (myhours > 12) ? myhours 12 : myhours; ampm = (myhours >= 12) ? 'Bu i Chi u ' : ' Bu i S ng '; mytime = mydate.getMinutes(); myminutes = ((mytime < 10) ? ':0' : ':') + mytime; if(myday == 0) day = " Ch Nh t , "; else if(myday == 1) day = " Th hai, "; else if(myday == 2) day = " Th ba, "; else if(myday == 3)
JAVASCRIPT
PAGE: 14
day = " Th t, "; else if(myday == 4) day = " Th n m, "; else if(myday == 5) day = " Th s u , "; else if(myday == 6)
day = " Th b y , ";
if(mymonth == 0) { month = "th ng m t ";} else if(mymonth ==1) month = "th ng hai "; else if(mymonth ==2) month = "th ng ba "; else if(mymonth ==3) month = "th ng t "; else if(mymonth ==4)
month = "th ng n m, ";
else if(mymonth ==5) month = "th ng s u "; else if(mymonth ==6) month = "th ng b y "; else if(mymonth ==7) month = "th ng t m "; else if(mymonth ==8) month = "th ng chn "; else if(mymonth ==9) month = "th ng m i "; else if(mymonth ==10) month = "th ng m i m t "; else if(mymonth ==11) month = "th ng m i hai "; // End --> </script>
<body> <script> document.write("<b><font color=#0000ff face='VNITimes,helvetica,arial'>" + ampmhour + "" + myminutes + ampm) document.write(" - " + day + " ng y " + myweekday +" "); document.write( month + " , n m " + year + "</font>"); </script>
</body>
trong form.
Khi s dng b qun l s kin bn c th vit cc hm biu din cho cc hnh ng da vo
cc s kin oc chn
PAGE: 15
Tn s kin
M t Xy ra khi im tp trungca ng vo c di chuyn ra khi mt thnh phn ca Form (Khi user click ra ngoi mt trng) Khi user Click vo 1 link hoc thnh phn ca Form. Xy ra khi gi tr ca Form Field b thay i bi user. Xy ra khi ng vo tp trung vo thnh phn ca Form Xy ra khi mt trang c Load vo trong b duyt. Xy ra khi User di chuyn mouse qua mt Hyperlink. Xy ra khi User chn 1 trng ca thnh phn Form. Xy ra khi User xc nhn nhp xong d liu. Xy ra khi User ri khi trang Web.
blur
<INPUT TYPE=text onChange= if (parseInt(this.value) <= 5) { alert(Please enter a number greater than 5.);
}
>
V d:
<INPUT alert(Thanks for the entry.); confirm(Do you want to continue?); >
TYPE=text onChange=
T kha this: quy cho i tng hin hnh.Trong Javascript Form l m i tng.Cc thnh
phn ca Form bao gm text fields, checkboxes, radio buttons, buttons, v selection lists.
JAVASCRIPT
PAGE: 16
onBlur, onChange, onFocus onBlur, onChange, onFocus, onSelect onBlur, onChange, onFocus, onSelect OnClick onClick OnClick onClick, onMouseOver OnClick
OnClick Selection list Text element Textarea element Button element Checkbox Radio button Hypertext link Reset button Submit button
onLoad, onUnload
onLoad, onUnload onSubmit
Document
Window Form
Vi du:
<HTML> <HEAD> <TITLE>Example 5.1</TITLE> <SCRIPT LANGUAGE=JavaScript> <!-- HIDE FROM OTHER BROWSERS var name = ; // STOP HIDING FROM OTHER BROWSERS --> </SCRIPT> </HEAD> <BODY onLoad=
name = prompt(Ent er Your Name:,Na me); alert(Greeti ngs + name + , welcome to my page!); onUnload= alert(Goodb ye + name + , sorry to see you go!);> <IMG SRC=title. gif> </BODY> </HTML>
Vi du
MTWRFSS
<HTML> <HEAD>
JAVASCRIPT
PAGE: 17
<TITLE>Example 5.1</TITLE> <SCRIPT LANGUAGE=JavaScript> <!-- HIDE FROM OTHER BROWSERS // DEFINE GLOBAL VARIABLE var name = ; function hello() { name = prompt(Enter Your Name:,Name); alert(Greetings + name + , welcome to my page!);
}
// STOP HIDING FROM OTHER BROWSERS --> </SCRIPT> </HEAD> <BODY onLoad=hello(); onUnload=goodbye();> <IMG SRC=title.gif> </BODY> </HTML>
Cc s kin v Form
Cac s kin c s dng truy xut Form nh: OnClick, onSubmit, onFocus, onBlur, v onChange. V d:
expression,); calculate(form);
}
<TITLE>Example 5.3</TITLE> <SCRIPT LANGUAGE=JavaScript> <!-- HIDE FROM OTHER BROWSERS function calculate(form) { form.results.value = eval(form.entry.value);
}
function getExpression(form) {
//STOP HIDING FROM OTHER BROWSERS --> </SCRIPT> </HEAD> <BODY> <FORM METHOD=POST> Enter a JavaScript mathematical expression: <INPUT TYPE=text NAME=entry VALUE= onFocus=getExpression(this.form);> <BR>
PAGE: 18
JAVASCRIPT MEDIASPACE CLUB (HTD)
The result of this expression is: <INPUT TYPE=text NAME=results VALUE= onFocus=this.blur();>
MTWRFSS
formObjectName.fieldname:Dng ch tn trng ca hin hnh trong Form. formObjectName.fieldname.value: dng ly gi tr ca trng form hin hnh. S dng vng lp trong JavaScript 1 . Vng lp for : C php : for ( init value ; condition ; update expression ) V d : for (i = 0 ; i < 5 ; i++) { lnh ; }
V d:
<HTML> <HEAD> <TITLE> for loop Examle </TITLE> </HEAD> <BODY> <SCRIPT LANGUAG E="JavaScri pt"> <!- var name=prom pt("What is
your name?" ,"name"); var query= " " ; document.write("<H1>" + name + " 's 10 favorite foods </H1> "); for (var i=1 ;i<=10;i++) {
JAVASCRIPT
PAGE: 19
document.write(i + " " + prompt('Enter food number ' + i, 'food' ) + '<BR>'); } - -> </SCRIPT> </BODY> </HTML>
2 . Vng lp while : C php: While ( iu kin) { lnh JavaScript ; } V d: var num=1; while(num<=10) { document.writeln(num); num++; } V d: var answer= ; var correc=100; var question= what is 10*10 ? ; while(answer!=correct) { answer=prompt(question,0); } 3. To mng vi vng lp for: function createArray(num) { this.length=num; for ( var j=0 ; j<num; j++) this[j]=0; }
Hm s to mt mng c gi tr index bt u l 0 v gn tt c cc gi tr ca mng v 0 .
s dng i tng mng ta c th lm nh sau: newArray= new createArray(4) S to ra mt mng gm 4 thnh phn newArray[0] NewArray[3]
PAGE: 20
JAVASCRIPT MEDIASPACE CLUB (HTD)
S dng i tng Windows Window l i tng ca mi trng Navigator,ngoi cc thuc tnh Window i tng window
cn gi cc i tng khc m c th c xem nh l cc thnh phn (member) ca window,
tham kho n cc thnh phn trong trang HTML. 1) Cc thuc tnh (properties) ca i tng document a . alink b . anchor c . bgColor d . cookies e . fgColor f . form g . lastModified h . linkColor i . links j . location k . referrer l . title m . vlinkColor 2) Cc hnh vi (Methods) ca i tng document a . clear() b . close() c . open() d . write() e . writeln() 3) Cc thuc tnh ca i tng Window a . defaultStatus : Gi tr mt nhin c hin th thanh trng thi b . frames : Mng cc i tng cha ng mt mc cho mi frame con trong mt frame ti liu c . parent : c s dng trong FRAMSET d . self : Ca s hin hnh , dng phn bit gia cc ca s hin hnh v cc forms c cng tn . e . status : Gi tr ca chui vn bn c hin th ti thanh status bar.Dng hin thi cc thng bo cho ngi s dng . f . top : nh cao nht ca ca s cha
JAVASCRIPT
MEDIASPACE CLUB
(HTD)
PAGE: 21
g . window 4) Cc hnh vi (Methods) ca i tng window a . alert() : Hin 1 thng bo trong hp thoi vi OK button. b . close() : ng ca s hin hnh. c . open() : M mt ca s mi vi 1 ti liu c ch ra hoc m mt ti liu trong mt tn ca s c ch nh. d . prompt() : Hin mt hp thng bo e . setTimeout() : f . clearTimeout() : Hnh vi ny cung cp cch gi pht biu JavaScript sau mt khong thi gian tri qua .Ngoi ra i tng window c th thc hin event handler : onLoad=statement Lm vic vi status bar Khi user di chuyn qua mt hyperlink ta c th hin ra mt thng bo ti thanh status bar ca bowser da vo event handler onMouseOver v bng cch t self.status l mt chui (hoc window.status). V d:
<HTML> <HEAD> <TITLE>Status Example</TITLE> <BODY> <A HREF=plc.htm onMouseOver=self.status=Chuyen de PLC ;return true ; >Lop chuyen d PLC </A> <A HREF=tkweb.htm onMouseOver=self.status=Thiet Ke Trang Web ;return true ; >Thiet Ke Web</A> </BODY> </HTML>
M v ng cc ca s S dng phng php open() v close() ta c th iu khin vic m v ng ca s cha ti liu. open (URL , WindowName , featureList) ; Cc c im trong phng php open() gm c: toolbar : to mt toolbar chun location: to mt vng location directories: to cc button th mc chun status: to thanh trng thi. menubar : to thanh menu ti nh ca ca s scrollbars: to thanh scroll bar resizable: cho php user thay i kch thc ca s width : ch nh chiu rng ca s theo n v pixel height : ch nh chiu cao ca s theo n v pixel V d: window.open( plc.htm,newWindow,toolbar=yes,location=1,directories=yes,status=yes,
MEDIASPACE CLUB (HTD)
JAVASCRIPT
PAGE: 22
menubar=1,scroolbar=yes,resizable=0,copyhistory=1,width=200,height=200); V d:
<HTML> <HEAD> <TITLE>WINDOWS</TITLE> <SCRIPT LANGUAGE="JavaScript"> <!-function openWindow(url,name) { popupWin = window.open(url, name, "scrollbars=yes,width=800, heigth=200 ");
</BODY> </HTML>
<HTML> <HEAD> <TITLE>Close Example</TITLE> </HEAD> <BODY > <A HREF="#" ONCLICK="self.close();return false"><IMG ALIGN="middle" SRC="../demo.gif" WIDTH="16" HEIGHT="16" BORDER="0"></A> <A HREF="#" ONCLICK="self.close();return false">Close This Sample</A> </BODY > </HTML>
S dng i tng string String l mt i tng ca JavaScript,khi dng i tng string chng ta khng cn cc pht
biu to mt instance (th nghim) ca i tng ,bt k lc no ta t text gia hai du
ngoc kp v gn n n mt bin hoc mt thuc tnh th ta to mt i tng string. 1. Cc thuc tnh ca i tng string Thuc tnh length gi s k t ca string. 2. Cc hnh vi (Methods) ca i tng string a . Anchor (nameAttribute) b . big() c . blink() d . bold() e . charAt(index) f . fixed() g . fontcolor(color)
MEDIASPACE CLUB (HTD) JAVASCRIPT
PAGE: 23
h . fontsize(size) i . indexOf(character,[fromIndex]) j . italics() k . lastIndexOf(character,[fromIndex]) l . link(URL) m . small() n . strike() o . sub() p . substring(startIndex,endIndex) q . sup() r . toLowerCase() s . toUpperCase()
PAGE: 24