Giáo trình Lập trình web
Bạn đang xem 20 trang mẫu của tài liệu "Giáo trình Lập trình web", để tải tài liệu gốc về máy bạn click vào nút DOWNLOAD ở trên
Tài liệu đính kèm:
- giao_trinh_lap_trinh_web.pdf
Nội dung text: Giáo trình Lập trình web
- CHÖÔNG 0 : GIÔÙI THIEÄU VEÀ WEB I. World Wide Web _ WWW : WWW thöøông ñöïôc goïi laø taét laø Web. Web laø moät maïng maùy tính coù qui moâ toaøn theá giôùi. Taát caû caùc maùy tính trong Web coù theå truyeàn thoâng vôùi nhau. Taát caû caùc maùy tính söû duïng moät nghi thöùc chuaån goïi HTTP. Thoâng tin Web ñöïôc caát giöõ trong nhöõng taøi lieäu goïi laø nhöõng trang Web. Nhöõng trang Web laø nhöõng taäp tin caát giöõ trong nhöõng maùy tính goïi laø nhöõng server Web. Nhöõng maùy tính ñoïc nhöõng trang Web ñöïôc goïi nhöõng Web clients.Nhöõng Web client xem nhöõng trang vôùi moät chöông trình goïi laø moät trình duyeät Web hay Web browser. Moät trình duyeät taûi moät trang Web töø server thoâng qua moät yeâu caàu HTTP chuaån chöùa moät ñòa chæ trang URL. Taát caû caùc trang Web chöùa ñöïng nhöõng leänh ñeå trình baøy. Trình duyeät trình baøy trang thoâng qua vieäc ñoïc nhöõng leänh naøy. Nhöõng leänh trình baøy chung nhaát ñöïôc goïi theû HTML. II. HTML : HTML vieát taét cuûa “Hyper Text Markup Language”. Moät file HTML laø moät taäp tin vaên baûn chöùa ñöïng theû ñaùnh daáu. Theû ñaùnh daáu noùi cho trình duyeät Web laøm sao ñeå trình baøy trang. Moät file HTML coù theå ñöïôc taïo ra baèng caùch söû duïng moät chuöông trình soaïn thaûo vaên baûn ñôn giaûn nhö notepad, textpad, 1. Theû HTML : Nhöõng theû HTML ñöïôc söû duïng ñeå ñaùnh daáu nhöõng phaàn töû HTML. Nhöõng theû HTML ñöïôc bao bôûi hai kí töï ' '. Nhöõng theû HTML khoâng phaûi phaân bieät chöõ thöôøng, chöõ hoa Theû HTML chi laøm 2 nhoùm chính : . Theû ñieàu khieån (theû roãng) : chæ goàm moät theû duy nhaát. . Theû noäi dung (phaàn töû HTML) : bao goàm moät caëp theû. Theû ñaàu tieân trong moät caëp laø theû môû , theû (thöù) hai laø theû ñoùng. Vaên baûn giöõa theû môû vaø theû ñoùng laø noäi dung Ví duï : 2
- Title of page This is my first homepage. This text is bold 2. Thuoäc tính theû Nhöõng theû coù theå coù nhöõng thuoäc tính Nhöõng thuoäc tính coù theå cung caáp theâm caùc thoâng tin veà nhöõng phaàn töû HTML treân trang web. Nhöõng thuoäc tính luoân luoân ôû daïng "teân = giaù trò" Ví duï: Theû ñònh nghóa noäi dung trang HTML .Vôùi moät thuoäc tính bgcolor ñöïôc theâm, chuùng ta coù theå noùi vôùi trình duyeät raèng neàn trang caàn phaûi ñoû. 3
- CHÖÔNG 1 : HTML I Caáu truùc toång quaùt cuûa moät trang Web II Phaàn Header 1. Theû 2. Theû 3. Theû III Phaàn Body 1. Caùc theû hoå trôï cho ñònh daïng vaên baûn a. Ñònh daïng cho caùc ñoaïn vaên: ñònh nghóa vaên baûn in ñaäm ñònh nghóa vaên baûn in lôùn ñònh nghóa vaên baûn ñöïôc nhaán maïnh ñònh nghóa vaên baûn nghieâng ñònh nghóa vaên baûn nhoû ñònh nghóa vaên baûn ñaäm ñònh nghóa vaên baûn subscripted (chæ soá ) ñònh nghóa vaên baûn superscripted (soá muõ) ñònh nghóa vaên baûn gaïch döùôi. - ñònh nghóa heading 1 tôùi heading 6 Nhöõng heading ñöïôc ñònh nghóa töø theû ñeán theû . ñònh nghóa heading lôùn nhaát. 4
- ñònh nghóa heading nhoû nhaát. HTML töï ñoäng theâm moät doøng traéng tröùôc vaø sau moät heading. ñònh nghóa moät ñoaïn (paragraph) HTML töï ñoäng theâm moät doøng traéng theâm tröùôc vaø sau moät ñoaïn. ñònh nghóa moät phaàn töû ñòa chæ ñònh nghóa höùông vaên baûn noäi dung ñònh nghóa moät trích daãn daøi ñònh nghóa vaên baûn ñieän baùo ñònh nghóa vaên baûn ñöïôc taïo khuoân tröùôc. duøng ñeå xuoáng haøng Theû ñöïôc söû duïng khi baïn muoán keát thuùc moät doøng, nhöng khoâng muoán khôûi ñoäng paragraph môùi. Theû laø moät theû roång. Noù khoâng coù theû ñoùng. ñònh nghóa moät chuù thích trong maõ nguoàn HTML Theû chuù thích ñöïôc söû duïng ñeå cheøn moät chuù thích trong maõ nguoàn HTML.Moät chuù thích seõ ñöïôc boû qua bôûi trình duyeät. Chuù yù : caàn moät daáu'!' chæ sau moùc môû. b. Ñöôøng keû ngang : chieàu roäng : pixels, % höôùng : [right | left | center] noshare : taïo boùng c. Ñònh daïng danh saùch : + Danh saùch khoâng ñaùnh soá thöù töï Moät danh saùch khoâng thöù töï laø moät danh muïc. Moät danh saùch khoâng thöù töï baét ñaàu vôùi theû Moãi phaân töû danh saùch baét ñaàu vôùi theû . 5
- Beân trong moät phaân töû danh saùch chuùng ta coù theå ñaët chia ñoaïn, xuoáng doøng, nhöõng aûnh, nhöõng moái lieân keát, danh saùch khaùc ,v.v. item Ví duï : item 1 item 2 + Danh saùch ñöôïc ñaùnh soá thöù tö Moät danh saùch coù thöù töï cuõng laø moät danh muïc. Nhöõng phaân töû danh saùch ñöïôc ñaùnh daáu vôùi nhöõng soá. Moät danh saùch ñöïôc saép thöù töï baét ñaàu vôùi theû Moãi phaân töû danh saùch baét ñaàu vôùi theû . Beân trong moät phaân töû danh saùch chuùng ta coù theå ñaët chia ñoaïn, xuoáng doøng, nhöõng aûnh, nhöõng moái lieân keát, danh saùch khaùc ,v.v. ï item Ví duï : item 1 item 2 item 3 item 4 + Danh saùch töï ñònh nghóa Moät danh saùch töï ñònh nghóa khoâng phaûi laø danh muïc haøng hoùa. Danh saùch naøy laø moät danh saùch nhöõng phaàn töû vaø giaûi thích nhöõng phaàn töû ñoù. Moät danh saùch töï ñònh nghóa baét ñaàu vôùi theû . Moãi phaàn töû baét ñaàu vôùi theû . Moãi giaûi thích baét ñaàu vôùi theû . Beân trong moät phaân töû danh saùch chuùng ta coù theå ñaët chia ñoaïn, xuoáng doøng, nhöõng aûnh, nhöõng moái lieân keát, danh saùch khaùc ,v.v. 6
- Tieâu ñeà ñònh nghóa Ví du : RAM Read Access Memory d. Thöïc theå kyù töï : Vaøi kí töï coù moät nghóa ñaëc bieät beân trong HTML, nhö kyù töï ' greater than > > & ampersand & & " quotation mark " " ' apostrophe ' 7
- Result Description Entity Name Entity Number ¢ cent ¢ ¢ £ pound £ £ ¥ Yen ¥ ¥ § section § § © copyright © © ® registered trademark ® ® × multiplication × × ÷ division ÷ ÷ 2. Hình aûnh Trong HTML, hình aûnh ñöïôc ñònh nghóa vôùi theû .Theû laø theû roãng. Cuù phaùp : src : URL cuûa aûnh chuùng ta muoán trình baøy treân trang web align = [ top | bottom | middle | left | right ] ( default = middle ) width / height : ñònh kích thöôùc hình aûnh hspace / vspace : khoaûng caùch giöõa hình vaø chöõ ( ñôn vò pixels ) alt : ñöïôc söû duïng ñeå ñònh nghóa moät "chuù thích" cho moät aûnh. + Image Map Image Map baét buoäc phaûi coù height vaø width coords : danh saùch caùc ñoái soá phuï thuoäc vaøo shape rect : 4 ñoái soá (left – top – right – bottom ) circle : 3 ñoái soá ( x, y , r ) polygon : 2 * n ñoái soá Ví duï: 8
- 3. Sieâu lieân keát HTML söû duïng theû href : ñöïôc söû duïng ñeå höùông vaøo taøi lieäu caàn lieân keát , vaø noäi dung cuûa theû anchor seõ ñöïôc trình baøy nhuö moät hyperlink. target : ñònh nghóa nôi taøi lieäu ñöïôc lieân keát seõ ñöïôc môû. target =" _blank " Taûi taøi lieäu môùi trong moät cöûa soå môùi target =" _self " Taûi taøi lieäu môùi trong cuøng cöûa soå. target =" _parent " Taûi taøi lieäu môùi trong cöûa soå cha (frame) target =" _top " Taûi taøi lieäu môùi trong toaøn boä cöûa soå trình duyeät. Cuù phaùp 2: name : ñöïôc söû duïng ñeå taïo ra moät anchor coù teân.Khi söû duïng nhöõng anchor coù teân chuùng ta coù theå taïo ra nhöõng moái lieân keát maø coù theå nhaûy tröïc tieáp vaøo trong moät ñoaïn ñöïôc chæ roõ trong moät trang Ví duï : Caàn phaûi chuù yù moät coù teân maø anchor khoâng trình baøy trong moät caùch ñaëc bieät. Ñeå lieân keát tôùi anchor coù teân, chuùng ta theâm daáu '#' vaø teân anchor sau URL. Ví duï : Nhöõng anchor coù teân thöôøng ñöïôc söû duïng ñeå taïo ra " muïc luïc " ôû khi baét ñaàu moät taøi lieäu lôùn. Moãi chöông beân trong taøi lieäu ñöïôc gaùn cho moät anchor coù teân, vaø nhöõng moái lieân keát tôùi taát caû nhöõng anchor ñöïôc ñaët taïi ñænh taøi lieäu. Neáu moät trình duyeät khoâng theå tìm thaáy moät teân anchor, noù seõ troû ñeán ñænh taøi lieäu. Khoâng xuaát hieän loãi ôû ñaây. 9
- Chuù yù : neân söû duïng ñöôøng daãn töông ñoái trong caùc sieâu lieân keátNeân + Ñöôøng daãn töông ñoái / : veà thö muïc cha MY FOLDER H I. htm A D. htm E. htm B F. htm C G. htm - Töø F.htm ñeán D.htm - Töø I.htm ñeán F.htm 4. Table Nhöõng baûng ñöïôc ñònh nghóa vôùi theû . Moät baûng ñöïôc chia vaøo trong nhöõng haøng vôùi theû , vaø moãi haøng ñöïôc chia caét thaønh caùc ñôn vò vôùi theû . Moät ñôn vò coù theå chöùa ñöïng nhöõng vaên baûn, nhöõng aûnh, nhöõng danh saùch, nhöõng ñoaïn, nhöõng form, thanh ngang, table khaùc, v.v. Moät baûng toång quaùt coù daïng nhö sau : // doøng a b c d 10
- a. Caùc thuoäc tính cuûa theû TABLE Cuù phaùp : frame : keát hôïp vôùi thuoäc tính border ñeå ñònh daïng khung cuûa table. Frame ñaët ngay beân phaûi cuûa table, coù caùc giaù trò sau void : khoâng coù khung above : canh treân below : canh döôùi lhs : canh traùi rhs : canh phaûi hsides : canh treân vaø döôùi vsides : canh traùi vaø phaûi box : canh 4 beân (default ) border : ñoä daøy cuûa khung _ Neáu chuùng ta khoâng chæ roõ moät thuoäc tính border table seõ ñöïôc trình baøy maø khoâng coù khung. width : chieàu roäng cuûa table height : chieàu cao cuûa table bgcolor : maøu neàn cuûa table cellspacing : khoaûng caùch giöõa caùc Cells cellpadding : khoaûng caùch giöõa caùc döõ lieäu vaø vaùch rules : [ cols | rows | all | groups ] ñònh daïng ñöôøng phaân caùch caùc cell b. Nhoùm caùc Cell Nhoùm caùc cell baèng 2 thuoäc tính colspan & rowspan cuûa theû colspan : nhoùm caùc cell theo coät. rowspan : nhoùm caùc cell theo haøng. Ví duï 1 : 11
- Keát quaû Ví duï 2 : Keát quaû Ví duï 3 : 12
- Keát quaû b. Caùc theû hoå trôï cho baûng + Theû : teân cuûa table Cuù phaùp : teân table Ví duï: TABLE 1 a b + Theû : töïa ñeà cho caùc coät ( in ñaäm ) Xuaát hieän treân moãi trang in neáu daøi hôn 1 trang. Söû duïng theû töông töï nhö söû duïng theû Ví duï: coät 1 13
- coät 2 a b + Theû : nhoù caùc coät Cuù phaùp : Caùc thuoäc tính ñöôïc thieát laäp trong seõ aûnh höôûng ñeán caùc coät lieân quan Xeùt table sau : Hoï vaø teân Ñòa chæ Baäc löông NVA 1.78 LVB 2:2 PTC 4.0 NVA 1.78 LVB 2.2 Ñeå traùnh laëp laïi nhieàu laàn duøng theû Hoï teân Ñòa chæ Baäc löông NVA 14
- 1.78 LVB 2.2 PTC 4.0 Chuù yù : Nhöõng cell khoâng coù noäi dung naøo chuöa ñöïôc trình baøy toát trong ña soá caùc trình duyeät. Nhöõng border xung quanh boä cell roãng bò bieán maát .Ñeå traùnh ñieàu naøy, theâm moät khoaûng traéng (& nbsp;) vaøo caùc cell troáng 5. Form : - Form laø cô cheá cho pheùp nhaän thoâng tin phaûn hoài töø ngöôøi söû duïng - Döõ lieäu seõ ñöôïc truyeàn ñeán WebServer ñeå xöû lyù vaø goïi/ taïo ra moät trang HTML traû lôøi Cuù phaùp : Caùc thaønh phaàn cuûa Form get : nhöõng thoâng tin leân header post : nhöõng thoâng tin trong Body Caùc thaønh phaàn cuûa Form bao goàm 3 loaïi theû chính Item 1 Item 2 MySite Item 3 15
- TextBox User Name Password Checkbox Radio Reset Reset Submit Submit Button File Hidden Image a. Theû : Cung caáp moät hoäp vaên baûn cho pheùp ngöôøi söû duïng coù theå nhaäp vaøo nhieàu doøng vaên baûn Cuù phaùp : Noäi dung ame : teân ñeå xaùc ñònh textarea trong form rows : soá doøng trong textarea cols : soá coät trong textarea wrap : xaùc ñònh caùch xöù lyù döõ lieäu tröôùc khi göûi . off : (default ) göûi noäi dung vaên baûn boû qua caùc kyù töï xuoáng doøng . virtual : cho pheùp nhaäp kyù töï xuoáng doøng nhöng khoâng göûi ñi . physical : göûi noäi dung vaên baûn bao goàm caû kyù töï xuoáng doøng b. Theû : Cung caáp caùc coâng cuï giôùi haïn thoâng tin phaûn hoài Cuù phaùp : type : xaùc ñònh loaïi coâng cuï (checkbox, radio, button ) name : teân ñeå xaùc ñònh coâng cuï trong form value : noäi dung cuûa input 16
- + Textbox : cho pheùp chæ nhaäp moät doøng vaên baûn. Ña soá caùc trình duyeät, ñoä roäng maëc ñònh cuûa tröôøng vaên baûn laø 20 kí töï. type = “text” size= kích thöôùc cuûa text box (tính theo soá kyù töï) maxlength= soá kyù töï toái ña ñöôïc nhaäp value = vaên baûn xuaát hieän trong textbox. + Password: töông töï nhö textbox nhöng noäi dung nhaäp ñöôïc che baèng maët naï (daáu ‘*’). type = “password” + Checkbox : danh saùch caùc tuøy choïn type = “checkbox” checked : caùc tuøy choïn ñöôïc choïn löïa maëc ñònh + Radio button : gom nhoùm danh saùch caùc löïa choïn ( chæ cho pheùp choïn 1 löïa choïn maø thoâi ) type = “radio” checked : tuøy choïn maëc ñònh Caùc löïa choïn trong cuøng moät nhoùm seõ coù cuøng teân Ví duï Nam Nu Gioi tinh : Nam Nu + Hidden : truyeàn ngaàm caùc giaù trò ñeán Web Server & Script ( duøng ñeå xöû lyù ) type = “ Hidden “ + Reset button : xoùa döõ lieäu trong Form type = “reset” + Submit button : göûi döõ lieäu töø Form leân Server type = “ Submit” c. Theû Duøng ñeå taïo Combo box vaø ListBox Cuù phaùp löïa choïn 17
- name : teân ñònh danh size = 1 : COMBOBOX > 1 : LISTBOX multiple (size > 1) cho pheùp löïa choïn nhieàu doøng Löu yù : + Giaù trò nhaäp vaøo cho Form caàn phaûi ñöôïc laøm cho coù hieäu löïc treân trình duyeät, baèng caùc ñoaïn maõ client Script . Vieäc kieåm tra giaù trò treân trình duyeät coù thôøi gian taùc ñoäng nhanh hôn, vaø giaûm bôùt söï truyeàn taûi treân server. + Chuùng ta caàn phaûi xem xeùt vieäc kieåm tra giaù trò treân server neáu döõ lieäu ñöôïc cheøn vaøo vaøo trong moät cô sôû döõ lieäu. + Moät toát caùch ñeå kieåm tra giaù trò treân Form laø seõ göûi giaù trò cho chính Form ñoù tröôùc, thay vì nhaûy tôùi moät trang khaùc. Ngöôøi duøng seõ nhaän ñöôïc nhöõng thoâng baùo loãi treân cuøng moät trang chöùa Form. Vieäc naøy seõ khaùm phaù loãi deã daøng hôn . 18
- IV. Frame Vôùi frame, chuùng coù theå trình baøy nhieàu taøi lieäu HTML trong cuøng cöûa soå trình duyeät.Moãi taøi lieäu HTML ñöïôc goïi moät khung, vaø moãi khung ñoäc laäp nhöõng khung khaùc. Moãi taøi lieäu coù theå caäp nhaät rieâng bieät. Nhöõng söï baát lôïi vieäc söû duïng frame : . Nguôøi phaùt trieån Web phaûi theo doõi nhieàu taøi lieäu HTML hôn . Khoù khaên ñeå in toaøn boä trang Frame thích hôïp cho caùc loaïi giao dieän sau : . Lieân keát chæ muïc . Nhöõng thaønh phaàn giao dieän coá ñònh . Giao dieän daïng hình xem aûnh hay taøi lieäu Single Page Master Page ( Frame) Top.htm Table Left.htm Right.htm - Maøn hình chæ xuaát hieän moät trang duy nhaát - Maøn hình xuaát hieän nhieàu trang - Coù theû - Khoâng coù theû - Caäp nhaät 1 vuøng ó caäp nhaät - Caäp nhaät töøng vuøng rieâng bieät toaøn trang * Trình baøy trang web thoâng thöôøng Site Navigation ( Bannner – Logo – Button ) Section Content Tools Navigation ( noäi dung töøng trang rieâng leû ( Coâng cuï trôï ( aûnh höôøng treân ) giuùp ) töøng nhoùm trang moät ) 19
- * Moät trang frame toång quaùt coù daïng sau : rows, cols : soá doøng, coät trình baøy trong moät frameset src : trang htm caàn load trong khung scrolling : coù thanh scroll bar hay khoâng nosize : khoâng cho pheùp thay ñoåi kích thöôùc khung marginwidth : chieàu roäng 2 caïnh treân vaø döôùi marginheight : chieàu roäng 2 caïnh traùi vaø phaûi a. Töø 1 trang ñôn -> frame Duøng sieâu lieân keát thoâng thöôøng trong trang ñôn ñeå goïi ñeán frame Ví duï : b. Töø 1 frame -> trang ñôn Duøng sieâu lieân keát coù thuoäc tính TARGET = “_top ” Ví du :ï c. Töø 1 vuøng aûnh höôûng ñeán vuøng khaùc Duøng sieâu lieân keát coù thuoäc tính TARGET vôùi giaù trò laø teân cuûa vuøng bò taùc ñoäng. Ví duï : 20
- CHÖÔNG 2 : DHTML I. JavaScript 1. Caùch nhuùng caùc ñoaïn code vaøo trong HTML: Ñeå nhuùng caùc ñoaïn code vaøo trong HTML, ngöôøi ta duøng theû Cuù phaùp : Ví duï : document.write("Hello World!") script: - chaïy treân client browser -> coù theå xem code. - chaïy treân server (thoâng dòch bôûi server) . Vò trí ñaët script trong trang HTML : + Ñaët trong phaàn header : script seõ ñöôïc load tröôùc khi trang web ñöôïc trình baøy. some statements 21
- + Ñaët trong phaàn body : script seõ ñöôïc söû duïng ñeå can thieäp vaøo caùch trình baøy noäi dung cuûa trang. some statements + Ñaët giöõa header vaø body : taêng tính roõ raøng giöõa caùc ñoaïn code trong trang HTML, script seõ ñöôïc xöû lyù tröôùc khi trang ñöôïc trình baøy. some statements Aån daáu script: Caùch vieát ngaén cho caùc script chaïy treân server. example <% //code 22
- %> Trong moät trang web coù theå coù nhieàu ñoaïn script. 2. Bieán : Bieán laø moät choå chöùa maø chuùng ta caàn ñeå löu giöõ thoâng tin. Giaù trò cuûa bieán coù theå thay ñoåi trong quaù trình thöïc thi. Ngöôøi ta tham khaûo moät bieán thoâng qua teân cuûa noù. Javascript khai baùo bieán thoâng qua töø khoaù var. Bieán trong Javascript xaùc ñònh ñöôïc kieåu thoâng qua giaù trò ñöôïc gaùn cho noù. Vd: var a,n,c; a = ”character” ; //a laø kieåu string. n = 15; //n laø kieåu int; c = 23.3 ; // c laø kieåu float. Moät bieán ñöôïc khai baùo beân ngoaøi moät thuû tuïc coù theå ñöôïc truy caäp vaø thay ñoåi bôûi baát kyø ñoaïn Script naøo trong trang web maø trong ñoù noù ñöôïc khai baùo. Moät bieán ñöôïc khai baùo beân trong moät thuû tuïc ñöôïc taïo ra vaø phaù huûy taïi moãi thôøi ñieåm thuû tuïc ñöôïc thöïc hieän. Khoâng coù ñoaïn Script naøo beân ngoaøi maø thuû tuïc coù theå truy nhaäp hoaëc thay ñoåi giaù trò cuûa bieán ñoù ñöôïc. Caùc kieåu döõ lieäu ñöôïc ñònh nghóa saún trong JavaScript Kieåu Ví duï Yù nghóa Soá nguyeân 125 Heä cô soá 10 0125 Heä cô soá 8 x125 Heä cô soá 16 Soá thöïc 1.75 1.75 2e3 2000 Chuoãi “hello” “135” 23
- Boolean true / false Null var x Khoâng xaùc ñònh kieåu Löu yù: Javascript cho eùp kieåu töø. Chuoãi ->soá nguyeân: duøng haøm parseInt. Vd: x=parseInt(“154”) ; //x chöùa giaù trò 154. Chuoãi -> soá thöïc: duøng haøm parseFloat Vd: x=parseFloat(“1.1214”); //x chöùa giaù trò 1.1214. Caùc toaùn töû thao taùc treân bieán : a.Toaùn töû ñaïi soá Toaùn töû Coâng duïng Ví duï Keát quaû + Coäng 2+2 4 - Tröø 5-2 3 * Nhaân 4*5 20 / Chia 15/5 3 5/2 2.5 % Modulo 5%2 1 10%8 2 ++ Taêng 1 x=5 x=6 x++ Giaûm 1 x=5 x=4 x b.Toaùn töû so saùnh Toaùn töû Coâng duïng Ví duï == So saùnh baèng 5==8 traû veà false != So saùnh khoâng baèng 5!=8 traû veà true > So saùnh lôùn hôn 5>8 traû veà false = So saùnh lôùn hôn hoaëc baèng 5>=8 traû veà false <= So saùnh nhoû hôn hoaëc baèng 5<=8 traû veà true 24
- c.Toaùn töû gaùn Toaùn töû Ví duï yù nghóa = x = y Gaùn giaù trò cuûa y sang cho x += 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 d.Toaùn töû ù Logic Toaùn töû Coâng duïng Ví duï && and x=6 y=3 (x 1) traû veà true || or x=6 y=3 (x==5 || y==5) traû veà false ! not x=6 y=3 x != y traû veà true e.Toaùn töû ñieàu kieän : Toaùn töû Ví duï yù nghóa ?: (x > y) ? 1 : 0 If(x>y) return 1; Else return 0; f.Toaùn töû chuoãi Toaùn töû Ví duï yù nghóa + x = “Hello ”; z=”Hello the world!” y = “the world!”; z= x+y; 25
- 2. Xuaát vaên baûn ra maøn hình: Ñeå xuaát vaên baûn ra maøn hình, ngöôøi ta thöôøng söû duïng 2 leänh : document.write(str). document.writeln(str). str: doøng maõ HTML. Ví duï: example document.write(" Hello World "); document.write("vi du"); document.write("tam biet"); 3. Caùc dialog thoâng thöôøng: a. alert _ cöûa soå thoâng baùo. Cuù phaùp: alert(“cau thong bao”)l Nhaäp: noäi dung caàn thoâng baùo. Traû veà: khoâng coù giaù trò traû veà. b. prompt _ nhaäp moät chuoãi töø ngöôøi duøng Cuù phaùp: prompt (“noi dung ”,“gia tri mac dinh”); Nhaäp: Giaù trò ñaàu laø noäi dung seõ xuaát hieän trong cöûa soå. Giaù trò 2 ñoaïn text seõ xuaát hieän trong textbox. Traû veà: chuoãi vaên baûn trong textbox. Ví duï: 26
- example document.write("day la cua so thu"+ prompt("nhap vao mot so","1")); c. confirm _ cho pheùp ngöôøi duøng xaùc nhaän ñuùng hay sai. Cuù phaùp: Confirm(“message”) Nhaäp: xuaát ra noäi dung caàn xaùc nhaän Traû veà: True neáu OK. False neáu Cancel. 7. Maûng: Maûng laø moät ñoái töôïngñaëc bieät trong javascript. Khai baùo maûng: var Teân_maûng = new Array([chieàu daøi | danh saùch giaù trò]) Ví duï : arrayName = new Array(); arrayName2 = new Array(7); arrayName3 = new Array(1,3,5); Löu yù: . Chieàu daøi maûng coù theå thay ñoåi: arr = ner Array(5); arr[15] = 6; //chieàu daøi maûng laø 16. .Caùc phaàn töû trong maûng coù theå khaùc loaïi. arr = new Array(“123”, 1, 9, new Array(4,2)); /* arr [0]= “123”; chuoãi. 27
- arr [1]= 1; kieåu int. arr [2]= 1.6; kieåu float. arr [3][0]= 4; arr [3][1]= 2; */ Thuoäc tính cuûa maûng: Length: cho bieát chieàu daøi cuûa maûng. Ví duï: Example 1 var arr = new Array(); document.writeln("chieu dai mang:" + arr.length); arr[99]=5; document.writeln("chieu dai cua mang:"+ arr.length); 8. Caùc leänh ñieàu khieån trong Javascript: a. Leänh if: Cuù phaùp: if (condition) { code to be executed if condition is true } [else { code to be executed if condition is false }] Ví duï: if (a>b) document.write("a>b"); else 28
- document.write("b>a"); b. Leänh while: Cuù phaùp: while (condition) { code to be executed } Ví duï : var i=1; var sum=0; while (i<10) { i *= 2; if(i==4)continue; sum + = i+ 1;// sum=29 } c. Leänh do while : Cuù phaùp : do { code to be executed } while (condition) d. Leänh for: Cuù phaùp: for (initialization; condition; increment) { code to be executed } Ví duï : for(i=0;i<10;i++) 29
- { arr[i]=i; } Cuù phaùp: for (attribute in object) { code to be executed } Ví duï : for(i in document) { document.writeln(i); } e. Leänh switch: Cuù phaùp: switch (expression) { case label1: code to be executed if expression = label1 break case label2: code to be executed if expression = label2 break [default: code to be executed if expression is different from both label1 and label2] } Ví duï : var s=1; switch (a) { case 1: s+="mot";break; case 2: s+="hai";break; 30
- case 3: s+="ba";break; default: s+="s khac 1, 2, 3"; } f. Leänh with: Cuù phaùp: with (ten_obj) { cau lenh; } Ví duï: with (document) { writeln("Hello World"); write("Good Bye") } 10. Haøm: Haøm laø moät khoái leänh coù theå ñöôïc söû duïng nhieàu laàn. Haøm ñöôïc thöïc thi bôûi moät söï kieän hoaëc moät leänh goïi haøm. Khai baùo haøm: function myfunction([argument1,argument2,etc ]) { some statements [return gia tri]; } Ví duï: function chan() { document.write(“Hello”); } Ví duï : function gt(n) //n! 31
- { if(n==1) return 1; else return gt(n-1)*n; } var x = gt(5); Thuoäc tính cuûa haøm: . argument: array chöùa caùc thoâng soá cuûa haøm. Ví duï : function hello() { document.write(“Hello”); document.write(hello argument.length); } hello(5,2,1); hello(); 11.Söï kieän vaø ñieàu khieån cuûa söï kieän Trình baøy Caäp nhaät trình baøy Javascript User Browser handle Mouse & Mouse & Keyboard action Keyboard Event * Caùc loaïi söï kieän Event What it handles onabort User thoaùt khoûi 1 trang ñang load onblur User rôøi khoûi moät object onchange User thay ñoåi value cuûa moät object onclick User click treân moät object ondblclick User double click treân moät object onfocus User laøm moät object trôû neân active 32
- onkeydown Khi moät phím treân baøn phím bò nhaán xuoáng onkeypress Khi moät phím treân baøn phím bò nhaán xuoáng vaø giaûi phoùng onkeyup Khi moät phím treân baøn phím ñöôïc giaûi phoùng onload Khi moät trang ñaõ load xong onmousedown Khi mouse-button bi nhaán xuoáng onmousemove Khi cursor di chuyeån treân moät object onmouseover Khi cursor di chuyeån ra khoûi moät object onmouseout Khi cursor di chuyeån vaøo moät object onmouseup Khi mouse-button ñöôïc giaûi phoùng onreset User nhaán button reset treân form onselect User choïn moät moät vuøng treân trang web onsubmit User nhaán button submit treân form onunload User rôøi khoûi moät trang * Ñieàu khieån söï kieän Ví duï: Ví duï 1 : Ñeám soá laàn mouse treân 1 hyperlink +Vuøng caàn baét söï kieän : hyperlink + Event caàn baét söï kieän : mouseover +Xöû lyù in ra soá laàn mouseover vi du 1 var count = 0 ; function thoângbaùo() { count ++; alert (“ soá laàn mouse laø : “ + count) ; } Ví duï 2: Taïo ra 1 hyperlink ñöôïc ñònh höôùng theo tuoåi cuûa ngöôøi söû duïng. 33
- Ex: Neáu ngöôøi söû duïng döôùi 30 tuoåi hyperlink seõ chæ ñeán www.domain1.net. Neáu ngöôøi söû duïng treân 30 tuoåi hyperlink seõ chæ ñeán www.domain2.net +Vuøng baét söï kieän : hyperlink +Event caàn xöû lyù : click +Xöû lyù: yeâu caàu ngöôøi xöû duïng nhaäp vaøo tuoåi .Caên cöù treân tuoåi nhaäp vaøo browseer seõ chæ ñeán URL thích hôïp ví duï 2 function xuly() { var tuoi = prompt( “nhaäp vaøo tuoåi cuûa baïn”,”1); tuoåi=parseInt(tuoi) if ( tuoi * Xöû kyù caùc söï kieän treân form Thaønh phaàn Caùc söï kieän coù theå xöû lyù Form onsubmit , onreset Taát caû onfocus, onblur File , select onchange Textbox , textarea Textbox , textarea onselect Button , checkbox Radio , submit onclick Reset Button onmousedown , onmouseup Textarea onkeydown , onkeyup , onkeypress * Caùc haøm moâ phoûng caùc söï kieän blur () , submit () , click () VD : Baét caùc söï kieän onfocus , onblur 34
- textbox * Caùc object ñöôïc browser cung caáp window Object laø duy nhaát frames history location navigator document screen event document link : anchors : images : forms : applets : frames : scripts : body : selections : · Boå sung : Collection töông töï nhö array nhöng caùc thaønh vieân coù tính chaát “read-only” Thuoäc tính : length : soá thaønh vieân trong collection Haøm : + Item (arg | index) : truy vaán töøng phaàn töû trong collection arg : chæ soá , teân thaønh vieân +Key(index) : traû veà teân cuûa thaønh vieân. Document . all . length : traû veà taát caû caùc theû HTML var tempform = doccument . all . item (“ form1 ” ) var t = doccument . all . item (“ A” ) //document anchor var imgs = doccument . all . item (“ img ” ) //document images Ví duï: 35
- document . forms .item (“ form1”) . submit () ; ó document . form1 .submit () ; document . forms (“form1”).submit () ; Ví duï : Cho 1 form nhö hình veõ Input1 textbox Input2 - Nhaäp 1 chuoåi vaøo input1 .Baûn copy seõ xuaát hieän trong input2 - Input2 khoâng cho pheùp nhaäp - Yeâu caàu 1 + Vuøng taùc ñoäng input1 + Event xöû lyù : onchange + Xöû lyù : giaù trò trong input1 gaùn cho input2 - Yeâu caàu 2 + Vuøng taùc ñoäng input2 + Event xöû lyù : onfocus + Xöû lyù : goïi haøm blur () ví duï function xulyinput1() { document.f1.text2.value= document . f1.text1.value; } input1 input2 36
- * Window object Windown object laø object cao nhaát trong caùc object cuûa DHTML. Window pbject cung caáp caùc thoâng tin veà window vaø frame Properties Property Explanation clientInformation Traû veà navigator object closed Traû veà moät giaù trò boolean xaùc nhaän neáu cöûa soå ñaû ñoùng. complete Traû veà moät giaù trò boolean xaùc nhaän neáu cöûa soå ñaõ load xong defaultStatus Ñaët hoaëc nhaän thoâng tin trong status bar document Traû veà document object event Traû veà event object external Traû veà moät object trình baøy host cuûa trang web history Traû veà history object length Traû veà soá frame trong cöûa soå. location Traû veà location objetc name Ñaët hoaëc nhaän teân cuûa cöûa soå. navigator Traû veà the navigator object opener Traû veà 1 window object chöùa caùc thoâng tin veà cöûa soå ñaõ môû cöûa soå hieän thôøi parent Traû veà object cha cuûa frame hieän thôøi self Traû veà the current window object status Ñaët hoaëc nhaän thoâng tin trong status bar. top Traû veà window object cao nhaát (frame) Methods Method Explanation alert() Displays an alert box with a message and an OK button attachEvent() Attaches the function to an event, so that the function gets called whenever the event is fired blur() The window loses focus clearInterval() Clears the setInterval method 37
- clearTimeout() Clears the setTimeout method close() Closes the window confirm() Displays a confirm box with a message, an OK button, and a Cancel button detachEvent() Detaches a function from an event execScript() Enables you to execute a script focus() Sets the focus to a specified window moveBy() Moves the window's position. From the current position moveTo() Moves the window's position. To the specified position navigate() The window navigates to the specified URL open() Opens a new window print() Prints the window's document prompt() Displays a prompt box with a message and an input field resizeBy() Changes the window's size, by the specified x and y offsets resizeTo() Sets the window's size to the specified values scroll() Scrolls the window to the specified scroll position. Note: This method is deprecated in JavaScript 1.2. It has been replaced by scrollTo() scrollBy() Scrolls the window, from the current scroll position scrollTo() Scrolls the window to the specified scroll position setInterval() An expression is valuated each time the specified interval occurs setTimeout() An expression is valuated after the specified timeout has occurred showHelp() Displays a specified help file showModalDialog() Displays a modal dialog box that shows the specified HTML document showModelessDialog() Displays a modeless dialog box that shows the specified HTML document Ví duï 1: var w2=open (); w2.document.write (“ hello”) 38
- Hi Ví duï 2: //trang html1 . htm //trang html2 . htm var w2=open (“ “ , “f2 “) w2.document.write (“ day la trang 2”) Day la trang 1 Ví duï 3: var w2; function f () { 39
- w2 = open () ; w2 . document. Write (“new window”) ; } function f () { w2.close (); } * Document object Properties Name Explanation anchors Returns a collection of all the anchor elements in the document which have the name attribute specified applets Returns a collection of all the object elements which includes the applet element body Returns the body or the frameset element cookie Returns the cookies for this document, as a string domain Returns the domain name of this document's server forms Returns a collection of all the form elements in the document images Returns a collection of all the img elements in the document links Returns a collection of all the anchor an area elements in the document with the href attribute specified referrer Returns the URI of the page that linked to this page, as a string title Returns, or sets the title element for this document. In Netscape this property is read-only URL Returns the URL of this document Methods Name Explanation close() Closes a document opened by the open() method getElementById(ID) Returns the element with the specified ID attribute getElementByName(name) Returns a collection of all the elements with the specified name attribute open() Clears everything on the existing document, and opens a new document write(text) Writes the specified text to the document writeln(text) Writes a line of text to the document * Form object Properties Name Explanation acceptCharset Returns a list of character sets supported by the server 40
- action Returns, or sets, the action handler of the form elements Returns a collection of all form elements enctype Returns the content type of the submitted form length The number of form elements in the form method Returns, or sets the Http method for submitting the form name Returns, or sets the name of the form target Sets the frame to submit the form to Methods Name Explanation reset() Resets the inputs in the form, same functions as a reset button submit() Submits the form, same functions as a submit button * Input object : Properties Name Explanation accessKey Defines a keyboard key to access the input element accept A list of content types that a server processing this form will handle correctly align Vertically or horizontally aligns this input element alt Returns, or sets, the alternate text to write if the browser fails showing this input element checked Returns, or sets, whether a radio or checkbox is checked defaultValue Returns, or sets, the default value defaultChecked Sets the checked property to true, radio buttons and checkboxes only disabled Returns, or sets, the disabled property. form Returns the form element to this input element maxLength Returns, or sets, the maximum number of character in this text field name Returns, or sets, the name of the input element readOnly Returns, or sets, whether the input element is read only. text fields and password fields only size Returns, or sets, the number of character in a text field src Returns, or sets, the URI of the image an a submit button, The type attribute must be 'image' tabIndex Returns, or sets, this input element's position in the tab order type Returns the type of this input element useMap value Returns, or sets, the value of radio buttons and checkboxes Methods Name Explanation blur() The input element loses focus focus() The input element gets focus select() Makes this input element selected click() Makes a mouse click for these input elements: 'button', 'checkbox', 'radio', reset', and 'submit' 41
- * Select object Properties Property Description Disabled Sets or returns the disabled property Form Returns the form element to this select element Length Returns the number of option elements Multiple Sets or returns whether you can select multiple options name Sets or returns the name of the select element options Returns the option elements as a collection selectedIndex Returns the selected option element as a number size Sets or returns the number of visible options tabIndex Sets or returns this select element's position in the tab order type Returns the type of this select element value Methods Method Description add(option, insertBefore) Adds a new option to the option collection remove(index) Removes an option from the option collection blur() The element looses focus focus() The element gets focus * Option object Properties Property Description defaultSelected Sets this option to be selected as default disabled Sets or returns the disabled property Form Returns the form element to the option index Returns the index position of this option label Sets or returns the label of the option selected Sets this option to be selected Text Returns the text for this option Value Sets or returns the value of the option * Textarea object : Properties 42
- Property Description accessKey Defines a keyboard key to access the textarea element Cols Sets or returns the width of the textarea (in characters) defaultValue Sets or returns the default value of the textarea disabled Sets or returns the disabled property form Returns the form element to this textarea name Sets or returns the name of the textarea readOnly Sets or returns whether the textarea is read only rows Sets or returns the height of the textarea (in rows) tabIndex Sets or returns the textarea's position in the tab order type Returns the type of the textarea value Sets or returns the textarea's value Methods Method Description blur() The element looses focus focus() The element gets focus select() Selects the content of the element * Table object Properties Property Description Border Sets or returns the width of the table border Caption Returns the caption of the table cellPadding Sets or returns the space between the cell border and the cell content cellSpacing Sets or returns the space between cells Frame Specifies which borders to render Rows Returns a collection of all the rows in the table Rules Specifies which borders, inside the table, to render summary Sets or returns a description of the table tBodies Returns a collection of all the tbody elements in the table tFoot Returns the tfoot element of the table tHead Returns the thead element of the table width Sets or returns the width of the table Methods Method Description createCaption() Creates a table caption or returns the existing caption createTFoot() Creates a table footer or returns the existing footer createTHead() Creates a table header or returns the existing header deleteCaption() Deletes the existing table caption deleteTFoot() Deletes the existing table footer deleteTHead() Deletes the existing table header deleteRow(index) Deletes the specified table row 43
- InsertRow(index) Inserts a table row at the specified row number * TableRow object Properties Property Description align Sets the horizontal alignment of the cell content cells Returns a collection of the cells in this row ch chOff rowIndex Returns the index of this row, relative to the table sectionRowIndex Returns the index of this row, relative to the current section; thead, tfoot, or tbody vAlign Sets the vertical alignment of the cell content Methods Method Description deleteCell(index) Deletes a table cell at the specified index insertCell(index) Inserts a table cell at the specified index * TableCell object Properties Property Description abbr Sets or returns an abbreviation for header cells align Sets the horizontal alignment of the cell content axis Sets or returns the name of a group of headers cellIndex Returns the index number for this cell in the row ch chOff colSpan Sets or returns the colspan for this cell headers Returns a list of the id attribute's value for header cells rowSpan Sets or returns the rowspan for this cell scope vAlign Sets the vertical alignment of the cell content * Anchor object Properties Property Description accessKey Defines a keyboard key to access the anchor element Charset Sets or returns the character set to use with the linked resource 44
- Coords Sets or returns the coordinates of the anchor (depending on its shape) Href Sets or returns the URL of the linked resource Hreflang Sets or returns the language code to use with the linked resource Name Sets or returns the name of the anchor rel Defines the link relationship from the current document to the linked document rev Defines the link relationship from the linked document to the current document shape Sets or returns the shape of the anchor tabIndex Sets or returns the anchor's position in the tab order target Sets or returns where to open the linked resource type Sets or returns the content type of the linked resource Methods Method Description blur() The element looses focus focus() The element gets focus * Image object Properties Property Description Alt Sets or returns the alternate text to write if the image is not available Height Sets or returns the height of the image isMap Sets the image to be a server-side image map longDesk Sets or returns the URL for a long description of the image lowSrc Sets or returns the URL of the image (for clients with low-resolution) Name Sets or returns the name of the image Src Sets or returns the URL of the image useMap Sets the image to be a client-side image map Width Sets or returns the width of the image * FrameSet object Properties Property Description Cols Sets or returns the number of columns in the frameset Rows Sets or returns the number of rows the frameset * Frame object Properties Property Description frameBorder Returns the frame border height Sets or returns the height of the frame 45
- longDesc Sets or returns the URI that contains a long description of the frame marginHeight Sets or returns the margin height of the frame marginWidth Sets or returns the margin width of the frame name Sets or returns the name attribute of the frame scrolling Sets or returns whether the frame should have scroll bars or not src Sets or returns the URI of the frame content * History object - Haøm back (n) : di chuyeån ngöôïc laïi n laàn forward (n) : di chuyeån tôùi n laàn go (n) : di chuyeãn tôùi thaønh phaàn n trong history Bieán : length : soá caùc record coù trong history *Navigator object Properties Properties Explanation appCodeName Returns the code name of the browser appMinorVersion Returns the minor version of the browser appName Returns the name of the browser appVersion Returns the platform and the version of the browser browserLanguage Returns the current browser language cookieEnabled Returns whether cookies are enabled or not cpuClass Returns a string that indicates the CPU class of the browser's system onLine Returns whether the system is on line or not platform Returns the platform of the browser systemLanguage Returns the default language for the system userAgent Returns the HTTP user-agent userLanguage Returns the current user language *Location object -VD url =”http:// www. Mydomain.comimages/default.htm?user=’Name’” href= url protocol = “http” host = www.mydomain.com.80 port = 80 46
- pathname = “images/default.htm” search = “?user=’Name’” * Event object : Properties Properties Explanation altKey Returns whether the Alt key is pressed or not button Returns which mouse button is pressed, if any cancelBubble Sets or retrieves whether the current should bubble up the hierarchy or not clientX Returns the x coordinate of the cursor when the mouse is pressed clientY Returns the y coordinate of the cursor when the mouse is pressed ctrlKey Returns whether the Ctrl key is pressed or not dataFld Returns the data column that is affected by the oncellchange event fromElement Returns the object that the cursor is exiting keyCode Sets or retrieves the Unicode of the key that caused the event offsetX Returns the horizontal coordinate of the cursor, when the mouse is pressed offsetY Returns the vertical coordinate of the cursor, when the mouse is pressed propertyName Returns the name of the property that has changed reason Returns the reason for completion for a data source object recordset Returns a recordset if the object is a data provider repeat Returns whether the event is being repeated or not returnValue Sets or retrieves the value that will be returned from the event screenX Returns the x coordinate of the cursor, relative to the screen screenY Returns the y coordinate of the cursor, relative to the screen shiftKey Returns whether the Shift key is pressed or not srcElement Returns the object that fired the event srcFilter Returns the filter object that fired the onfilterchange event srcUrn Returns the universal resource name of the behavior that fired the event toElement Returns the object the user moves to type Returns the name of the event x Returns the cursor's x coordinate when event fired y Returns the cursor's y coordinate when event fired *Caùc object phuïc vuï cho vieäc xaùc ñònh döõ lieäu vaø tính toùan 1 .Array object - Cuù phaùp : var = new ; Array () ; //khoâng phaàn töû Array (size ) Array (tp1,tp2, .,tpn) -VD 47
- var myarray = new Array () for (i=0 ; i< 10 ; i ++) { myarray [i] = i; } x = myarray [4] Methods Explanation NN IE ECMA length Returns number of elements in the array 3.0 4.0 1.0 concat() Returns an array concatenated of two arrays 4.0 4.0 1.0 join() Returns a string of all the elements of an array 3.0 4.0 1.0 concatenated together reverse() Returns the array reversed 3.0 4.0 1.0 slice() Returns a specified part of the array 4.0 4.0 sort() Returns a sorted array 3.0 4.0 1.0 * Caùc haøm cuûa Array object a) concat - Muïc ñích : traû veà 1 maûng môùi , noái 2 maûng coù saün - Cuù phaùp : array1.concat (array2) - VD function concat_Array_Demo () { var a, b, c; a = new Array (0 , 1 ,2 ,3 , 4) ; b = new Array (5 , 6 ,7 ,8 , 9) ; c = a.concat (b) ‘ return c ; } b) join - Muïc ñích : noái caùc thaønh phaàn cuûa maûng thaønh 1 chuoåi - Cuù phaùp : array1.join (kyù töï phaân caùch) kyù töï phaân caùch coù theåâ laø 1 chuoåi string object -VD function JoinDemo() { var a ,b ; a = new Array (0 , 1 , 2, 3, 4 ) ; b = a. join (‘_’) ; // b= “0_1_2_3_4” return b ; } 48
- c) reverse - Muïc ñích : ñaûo ngöôïc thöù töï caùc thaønh phaàn trong array - Cuù phaùp : array1.reverse () ; - VD function ReverseDemo() { var a, b ; a = new Array (0 , 1 ,2 ,3 ,4); b = a. reverse () ; //b= 4,3,2,1 return b ; } d) slice - muïc ñích : traû veà moät phaàn cuûa array - cuù phaùp : array1.slice (start [,end]) -VD : function ReverseDemo() { var a, b ; a = new Array (0 , 1 ,2 ,3 ,4); b = a. slice (0 ,-1) ; //b= 0 , 1, 2 , 3 , 4 alert ( b ); } b = a .slice (1, 2) // b ={1} b = a .slice (1, 3) // b ={1,2} b = a .slice (0,- 2) // b ={0, 1, 2} e) Sort - Muïc ñích :traû veà 1 array ñaõ ñöôïc saép thöù töï theo kyù töï alphabeta -Cuù phaùp : array . sort () - VD function ReverseDemo() { var a, b ; a = new Array (1 , 2 ,9 ,12 ,11); b = a. sort () ; //b= (1 , 11, 12 , 2 , 9) alert ( b ); } 2) String object 49
- Properties Explanation NN IE ECMA length Returns the length of a string 2.0 3.0 1.0 Methods Explanation NN IE ECMA anchor() Returns the string as an anchor: 2.0 3.0 big() Returns the string, formatted to big: string 2.0 3.0 blink() Returns the string, blinking: string 2.0 bold() Returns the string bold: string 2.0 3.0 charAt() Returns the character at the specified index 2.0 3.0 1.0 charCodeAt() Returns the Unicode of the specified indexed character 4.0 4.0 1.0 concat() Returns two concatenated strings 4.0 4.0 fixed() Returns the string as teletype text: string 2.0 3.0 fontColor() Returns the string in the specified color: string fontSize() Returns the string in the specified size: string fromCharCode() The charCodeAt method vice versa. Returns the string 4.0 4.0 value of the specified Unicode. indexOf() Returns the index of the first time the specified character 2.0 3.0 occurs, or -1 if it never occurs, so with that index you can determine if the string contains the specified character. italics() Returns the string in italic: string 2.0 3.0 lastIndexOf() Same as indexOf, only it starts from the right and moves 2.0 3.0 left. link() Returns the string as a hyperlink: match() Behaves similar to indexOf and lastIndexOf, but the match 4.0 4.0 method returns the specified characters, or "null", instead of a numeric value. replace() Replaces the specified characters with new specified 4.0 4.0 characters. search() Returns an integer value if the string contains the 4.0 4.0 specified characters, if not it returns -1. slice() Returns a string containing the specified character index. 4.0 4.0 small() Returns the string formatted to small: 2.0 3.0 string split() Replaces the specified characters with a comma. 4.0 4.0 1.0 strike() Returns the string strikethrough: string 2.0 3.0 sub() Returns the string formatted to subscript: 2.0 3.0 string substr() Returns the characters you specified. (14,7) returns 7 4.0 4.0 characters, from the 14th character. substring() Returns the characters you specified. (14,7) returns all 2.0 3.0 1.0 characters between the 7th and the 14th. sup() Returns the string formatted to superscript: 2.0 3.0 string toLowerCase() Returns the string in lower case 2.0 3.0 1.0 toUpperCase() Returns the string in upper case 2.0 3.0 1.0 Coù hai nhoùm haøm trong string object 50
- * Nhoùm haøm thay ñoåi trong thuoäc tính cuûa chuoåi - anchor :theû neo - big : theû - blink : theû chöõ nhaép nhaùy - bold : theû chöõ ñaäm - fixed : theû chöõ text theo kieãu ñaùnh maùy - fontcolor - fontsize - link : lieân keát vôùi trang html khaùc - italics - small : chöõ nhoû - sub : theû H 2 O : H2O - sup : theû : H2 * Nhoùm haøm thao taùc treân chuoåi a) ChatAt - Muïc ñích : traû veà kyù töï taïi 1 vò trí xaùc ñònh trong chuoåi - Cuù phaùp : strVariable . charAt (index) // index ñöôïc tính töø 0 - VD : function CharAttext() { var str = “ABCDEFGHEJI” var s ; s = str.charAt (5) ; //s = ‘E’ return s ; } b) CharCodeAt - Muïc ñích : traû veà maõ kyù töï taïi 1 vò trí xaùc ñònh trong chuoåi - Cuù phaùp : str. charCodeAt (index) - VD : function CharCodeAttext() { var str = “ABCDEFGHEJI” var s ; s = str.charCodeAt (1) ; //s = ‘66’ maõ kyù töï B return s ; } 51
- c) Concat - Muïc ñích : noái 2 chuoåi thaønh 1 chuoåi - Cuù phaùp : strVar1 . concat (strVar2) // index ñöôïc tính töø 0 - VD : function ConcatDemo() { var str1 = “ABCD” var s tr2 = “EFGH”; var str3 = str1.concat (str2) ; return str3 ; } d) FromCharCode - Cuù phaùp : string . FromCharCOde (code1, ,coden) - VD : var test = String .FromCCharCode (112,108,97,105,110) ; e) indexof - Muïc ñích : traû veà vò trí cuûa chuoåi con trong chuoåi cha - Cuù phaùp : strVar . indexof (substr, startindex ) - VD : var str = “ABCD” var t = str.indexof(“B”) ; // t=1 var s = str.indexof (“CD”) ; s=2 Haøm traû veà vò trí giaù trò -1 neáu chuoåi con khoâng tìm thaáy trong chuoåi cha f) Lastindexof - Muïc ñích : traû veà vò trí baét ñaàu cuûa chuoåi con xuaát hieän sau cuøng trong chuoåi cha - Cuù phaùp : strVar .Last indexof (substr, startindex ) - VD : var str = “ABCD ABCD ABCD” var t = str. Lastindexof(“ABC “) ; // t=8 g) Replcae - Muïc ñích : thay theá 1 chuoãi con trong chuoåi cha bôûi 1 chuoåi khaùc - Cuù phaùp : strVar . replcae (start , replcae text) - VD : function replaceDemo() { 52
- var str = “The fox jumped over the dog” ; var s = str.replcae (“fox” , “pig”) return s ; } h) Search - Muïc ñích : theâm 1 chuoåi con baèng maët naï, neáu chuoåi con laø 1 chuoåi con bình thöôøng thì haøm naøy töông töï nhö haøm indexof i) Slice - Muïc ñích : traû veà 1 phaàn cuûa chuoåi - Cuù phaùp : strVar . slice (start [,end] ) (töông tö nhö haøm slice trong array) j) split - Muïc ñích : traû veà 1 maûng töø 1 chuoåi ñöôïc phaân taùch bôûi 1 chuoåi con - Cuù phaùp : strVar . split (substr) - VD : function replaceDemo() { var s = “The fox jumped over the dog” ; var ss = s.split (“_”) // ss = {“the”,”fox”,”jumped”,”over”,”the”,”dog”} return ss ; } k) Substr - Muïc ñích : traû veà 1 chuoåi con baét ñaàu baèng 1 vò trí xaùc ñònh coù 1 chieàu daøi xaùc ñinh - VD : function SubstrDemo() { var s = “The fox jumped over the dog” ; var ss = s.substr (1,3) // ss = “fox” return ss ; } + caùc bieán thaønh vieân :length : traû veà chieàu daøi chuoåi VD : s= “hello” Var t = s.length // t= 5 3. Date Object 53
- Methods Explanation NN IE ECMA Date() Returns a Date object 2.0 3.0 1.0 getDate() Returns the date of a Date object (from 1-31) 2.0 3.0 1.0 getDay() Returns the day of a Date object (from 0-6. 0=Sunday, 2.0 3.0 1.0 1=Monday, etc.) getMonth() Returns the month of a Date object (from 0-11. 2.0 3.0 1.0 0=January, 1=February, etc.) getFullYear() Returns the year of a Date object (four digits) 4.0 4.0 1.0 getYear() Returns the year of a Date object (from 0-99). Use 2.0 3.0 1.0 getFullYear instead !! getHours() Returns the hour of a Date object (from 0-23) 2.0 3.0 1.0 getMinutes() Returns the minute of a Date object (from 0-59) 2.0 3.0 1.0 getSeconds() Returns the second of a Date object (from 0-59) 2.0 3.0 1.0 getMilliseconds() Returns the millisecond of a Date object (from 0-999) 4.0 4.0 1.0 getTime() Returns the number of milliseconds since midnight 1/1- 2.0 3.0 1.0 1970 getT imezoneOffset() Returns the time difference between the user's computer 2.0 3.0 1.0 and GMT getUTCDate() Returns the date of a Date object in universal (UTC) time 4.0 4.0 1.0 getUTCDay() Returns the day of a Date object in universal time 4.0 4.0 1.0 getUTCMonth() Returns the month of a Date object in universal time 4.0 4.0 1.0 getUTCFullYear() Returns the four-digit year of a Date object in universal 4.0 4.0 1.0 time getUTCHourc() Returns the hour of a Date object in universal time 4.0 4.0 1.0 getUTCMinutes() Returns the minutes of a Date object in universal time 4.0 4.0 1.0 getUTCSeconds() Returns the seconds of a Date object in universal time 4.0 4.0 1.0 getUTCMilliseconds() Returns the milliseconds of a Date object in universal time 4.0 4.0 1.0 parse() Returns a string date value that holds the number of 2.0 3.0 1.0 milliseconds since January 01 1970 00:00:00 setDate() Sets the date of the month in the Date object (from 1-31) 2.0 3.0 1.0 setFullYear() Sets the year in the Date object (four digits) 4.0 4.0 1.0 setHours() Sets the hour in the Date object (from 0-23) 2.0 3.0 1.0 setMilliseconds() Sets the millisecond in the Date object (from 0-999) 4.0 4.0 1.0 setMinutes() Set the minute in the Date object (from 0-59) 2.0 3.0 1.0 setMonth() Sets the month in the Date object (from 0-11. 0=January, 2.0 3.0 1.0 1=February) setSeconds() Sets the second in the Date object (from 0-59) 2.0 3.0 1.0 setTime() Sets the milliseconds after 1/1-1970 2.0 3.0 1.0 setYear() Sets the year in the Date object (00-99) 2.0 3.0 1.0 setUTCDate() Sets the date in the Date object, in universal time (from 4.0 4.0 1.0 1-31) setUTCDay() Sets the day in the Date object, in universal time (from 0- 4.0 4.0 1.0 6. Sunday=0, Monday=1, etc.) setUTCMonth() Sets the month in the Date object, in universal time (from 4.0 4.0 1.0 0-11. 0=January, 1=February) setUTCFullYear() Sets the year in the Date object, in universal time (four 4.0 4.0 1.0 digits) setUTCHour() Sets the hour in the Date object, in universal time (from 4.0 4.0 1.0 0-23) setUTCMinutes() Sets the minutes in the Date object, in universal time 4.0 4.0 1.0 (from 0-59) 54
- setUTCSeconds() Sets the seconds in the Date object, in universal time 4.0 4.0 1.0 (from 0-59) setUTCMilliseconds() Sets the milliseconds in the Date object, in universal time 4.0 4.0 1.0 (from 0-999) toGMTString() Converts the Date object to a string, set to GMT time zone 2.0 3.0 1.0 toLocaleString() Converts the Date object to a string, set to the current 2.0 3.0 1.0 time zone toString() Converts the Date object to a string 2.0 4.0 1.0 4. Math object Properties Explanation NN IE ECMA E Returns the base of a natural logarithm 2.0 3.0 1.0 LN2 Returns the natural logarithm of 2 2.0 3.0 1.0 LN10 Returns the natural logarithm of 10 2.0 3.0 1.0 LOG2E Returns the base-2 logarithm of E 2.0 3.0 1.0 LOG10E Returns the base-10 logarithm of E 2.0 3.0 1.0 PI Returns PI 2.0 3.0 1.0 SQRT1_2 Returns 1 divided by the square root of 2 2.0 3.0 1.0 SQRT2 Returns the square root of 2 2.0 3.0 1.0 Methods Explanation NN IE ECMA abs(x) Returns the absolute value of x 2.0 3.0 1.0 acos(x) Returns the arccosine of x 2.0 3.0 1.0 asin(x) Returns the arcsine of x 2.0 3.0 1.0 atan(x) Returns the arctangent of x 2.0 3.0 1.0 atan2(x,y) Returns the angle from the x axis to a point 2.0 3.0 1.0 ceil(x) Returns the nearest integer greater than or equal to x 2.0 3.0 1.0 cos(x) Returns the cosine of x 2.0 3.0 1.0 exp(x) Returns the value of E raised to the power of x 2.0 3.0 1.0 floor(x) Returns the nearest integer less than or equal to x 2.0 3.0 1.0 log(x) Returns the natural log of x 2.0 3.0 1.0 max(x,y) Returns the number with the highest value of x and y 2.0 3.0 1.0 min(x,y) Returns the number with the lowest value of x and y 2.0 3.0 1.0 pow(x,y) Returns the value of the number x raised to the power of y 2.0 3.0 1.0 random() Returns a random number between 0 and 1 2.0 3.0 1.0 round(x) Rounds x to the nearest integer 2.0 3.0 1.0 sin(x) Returns the sine of x 2.0 3.0 1.0 sqrt(x) Returns the square root of x 2.0 3.0 1.0 tan(x) Returns the tangent of x 2.0 3.0 1.0 55
- II CSS _ Cascading Style Sheet : 1. Ñònh nghóa : CSS cô cheá cho pheùp söûa ñoåi moät soá thuoäc tính cuûa caùc theû coù saún vaø ñònh vò caùc thaønh phaàn cuûa trang Web. 2. Thay ñoåi thuoäc tính cuûa theû: Cuù phaùp: New Page 1 HTML_ tag.class {special formating} class: moät thöïc theå xaùc ñònh caùc ñònh daïng cho moät theû hay thaønh phaàn naøo ñoù cuûa trang HTML. Teân cuûa class neân ngaén goïn, deã hieåu, traùnh ñaët truøng vôùi caùc töø khoaù. Ví duï: New Page 1 H1.Italic {font-style : italic} P.red_caps {color: red; font-style:small caps} .blue_Helv {font-family: Helvetica,sans_script;color:blue} H2 {color:green} Hello World //khong gi thay doi Hello // chu Hello in nghieng. Vi du // Vi du in chu hoa nho, nau do. //font Helvetica. 56
- item 1 item 2 Chu xanh 2. Ñònh vò treân trang web: Ñònh vò laø moät phaàn môû roäng cuûa ñònh nghóa css. Ñònh vò cho pheùp taïo ra caùc vò trí töông ñoái cho caùc nhoùm theû HTML. Ñònh vò tuyeät ñoái cho pheùp coá ñònh caùc thaønh phaàn hay caùc nhoùm thaønh phaàn taïi vò trí naøo ñoù treân trang. Ví duï: #layer 1 { position : loaïi; top: number; left: number; width: number; height: number;} position: absolute : tuyeät ñoái. relative : töông ñoái. static: tónh. left: top width number+ units (100px, 2in) . height Ví duï: #layer 1 { position : absolution ; top: 100px; left:50px ; width:200px ; height:100px ;} 57
- Hello World Ñònh vò theo thaønh phaàncha absolute, relative. Heä toaï ñoä cuûa browser: static. static Thaønh phaàn cuûa cha top left top static (asolute) left Thaønh phaàn cuûa cha top relative left a. Ñònh vò tuyeät ñoái: Thaønh phaàn ñöôïc ñònh vò töông ñoái döïa treân toaï ñoä cuûa thaønh phaàn cha. Thaønh phaàn cha moãi thaønh phaàn ñeàu coù möùc ñieàu khieån naøo ñoù ñoái vôùi thaønh phaàn khaùc. Neáu thaønh phaàn chöùa thaønh phaàn coøn laïi thì thaønh phaàn chöùa laø thaønh phaàn cha vaø taïo ra moät heä toïa ñoä môùi cho thaønh phaàn con. b. Ñònh vò töông ñoái: Thaønh phaàn seõ ñöôïc ñònh vò töông ñoái döïa treân toaï ñoä maø noù seõ xuaát hieän trong thaønh phaàn cha. c. Ñònh vò tónh : Thaønh phaàn seõ ñöôïc ñònh vò theo toïa ñoä cuûa trình duyeät. 3. Theû vaø theû : Xaùc ñònh noäi dung cho moät vuøng. 58
- Trong vuøng xaùc ñònh, chuùng ta coù theå thao taùc nhö treân moät trang web ñôn. Ví duï: Noái caùc thaønh phaàn naèm treân moät doøng Ví duï: Hinh 01 Hình 02 Hình 03 Ví duï: Hình 01 Hình 02 Hình 03 59
- Ví duï: Hình h1.jpg vaø h2.jpg luoân naèm treân ñöôøng thaúng. Caùc theû vaø thöôøng ñöôïc hoå trôï bôûi caùc thuoäc tính ñònh vò. Ví duï: Hinh 01 Hinh 02 Ñeå coù theå laäp trình ñöôïc cho theû vaø theû khi xaây döïng caàn cho chuùng moät teân hay moät ID. Ví duï: Söû duïng file css beân ngoaøi: Ví duï: New Page 1 60
- CHÖÔNG 3 : ASP I Giôùi thieäu veà ASP. ASP ñöôïc vieát taét theo 3 chöõ Active Server Page , ASP laø moät chöông trình ñöôïc thöïc thi beân trong IIS (Internet Information Services, laø moät daïng dòch vuï thoâng tin ñöôïc tích hôïp beân trang caùc HÑH maùy chuû , IIS laø moät thaønh phaàn cuûa Windows 2000 , hoaëc beân trong WindowsNT Option Pack ) hoaëc laø PWS (Personal Web Server , cuõng töông töï nhö IIS nhöng nhoû hôn, ñöôïc söû duïng trong caùc HÑH Win95 , Win98) . ASP laø moät Coâng ngheä cuûa Microsoft .ChiliASP laø moät coâng ngheä maø chaïy ASP maø khoâng caàn HÑH Windows ,InstantASP laø coâng ngheä khaùc maø khi chaïy ASP cuõng khoâng caàn coù Windows . Moät taäp tin ASP cuõng töông töï nhö moät taäp tin HTML , Moät taäp tin ASP coù theå chöùa ñöïng vaên baûn , HTML , XML vaø caùc maõ script . Caùc Script trong taäp tin ASP ñöôïc xöû lyù ngay treân Server . Moät taäp tin ASP coù ñuoâI môû roäng laø *.asp Khi trình duyeät cuûa Client yeâu caàu moät taäp tin HTML , thì Server seõ traû veà moät taäp tin HTML , khi trình duyeät yeâu caàu moät taäp tin ASP , thì luùc ñoù IIS seõ chuyeån yeâu caàu ñoù ñeán vôùi cô cheá ASP (ASP Engine) , ASP Engine seõ ñoïc taäp tin ASP töøng doøng moät vaø thöïc thi caùc Script trong taäp tin ASP ñoù , vaø keát quaû seõ ñöôïc traû veà cho trình duyeät döôùi daïng HTML . ASP coù theå soïan thaûo, thay ñoåi hoaëc theâm bôùt noäi dung gioáng nhö trang WEB thoâng thöôøng , ñaùp laïi caùc caâu truy vaán cuûa Client vaø traû veà keát quaû hieån thò baèng trình duyeät , truy caäp cô sôû döõ lieäu , tuyø yù bieán ñoåi caùc trang WEB ñeå phuïc vuï cho caùc muïc ñích khaùc nhau . Lôïi ñieåm cuûa vieäc söû duïng ASP hôn nhöõng ngoân ngöõ khaùc nhö Perl , CGI laø ñôn giaûn vaø toác ñoä . Ngoaøi ra noù coøn cung caáp moät cô cheá baûo maät laø caùc code ñöôïc vieát trong moät taäp tin ASP seõ ñöôïc daáu kín vaø khoâng theå naøo coù theå thaáy ñöôïc baèng trình duyeät WEB maø chæ coù theå thaáy ôû daïng HTML maø thoâi. NgoaøI ra coøn coù moät lôïi ñieåm khaùc khi söû duïng ASP laø coù theå toái öu hoaù löu löôïng truyeàn taûi döõ lieäu treân maïng . 62
- II Application Object 1. Taùc duïng - Application object duøng ñeå chia seõ thoâng tin giöõa caùc user vôùi nhau trong 1 öùng duïng Web. Application xuaát hieän khi ngöôøi thöù nhaát yeâu caàu baát kyø file naøo trong thö muïc aûo maø öùng duïng ASP chöùa trong. Nhöõng bieán Application hieän höõu ôû taát caû caùc trang trong moät öùng duïng . Nhöõng bieán Application ñöôïc söû duïng ñeå giöõ thoâng tin veà taát caû caùc ngöôøi duøng trong moät öùng duïng . - Chuùng ta coù theå truy nhaäp thoâng tin cuûa bieán Application töø baát kyø trang naøo. Ñieàu ñoù cuõng coù nghóa raèng chuùng ta coù theå thay ñoåi thoâng tin trong moät nôI naøo ñoù vaø thoâng tin môùi seõ töï ñoäng ñöôïc phaûn chieáu treân taát caû caùc trang. - Nhöõng bieán Application phaûi ñöôïc taïo ra trong Global.asa nhöng chuùng coù theå ñöôïc truy nhaäp vaø thay ñoåi bôûi baát kyø trang naøo trong Application. Vieäc taïo naøy ñöôïc thöïc hieän bôûi söï kieän Onstart - Caùch khai baùo bieán Application (“teân bieán ”) =giaù trò ; 2. Collections Content Chöùa taát caû caùc thaønh phaàn ñöôïc theâm vaøo öùng duïng thoâng qua leänh script. StaticObject Chöùa taát caû caùc object ñöôïc theâm ñeán öùng duïng vôùi theû vaø coù taàm vöïc laø Application. 3. Methods Content.Remove Xoùa moät thaønh phaàn trong taäp hôïp Content Content.RemoveAll Xoùa taát caû caùc thaønh phaàn trong taäp hôïp Content. Lock Ngaên caùc client khaùc coù theå thay ñoåi noäi dung cuûa bieán Application. Unlock Cho pheùp caùc client khaùc coù theå thay ñoåi noäi dung cuûa bieán Application (sau khi ñaõ goïi haøm Lock() ). 4. Events Application_OnStart Söï kieän naøy xuaát hieän khi ngööôøi duøng ñaàu tieân goïi trang ñaàu tieân töø moät öùng duïng. Söï kieän naøy saún saøng sau khi Web server ñöôïc khôûi ñoäng laïi hoaëc sau khi Global.asa ñöôïc soaïn thaûo. Khi thuû tuïc naøy hoaøn taát, thuû tuïc " Session_OnStart " môùi chaïy. Application_OnEnd Söï kieän naøy xuaát hieän khi moät server döøng. Thuû tuïc naøy ñöôïc söû 63
- duïng ñeå ‘queùt doïn’ sau khi öùng duïng döøng ,gioáng nhö xoùa thoâng tin trong taäp tin vaên baûn. 64
- III. Session Object 1. Taùc duïng - Session object duøng ñeå chia xeû thoâng tin giöõa caùc trang web trong moät keát noái (server - browser). Nhöõng bieán Session caát giöõ thoâng tin veà moät user vaø thoâng tin ñoù saün saøng tôùi taát caû caùc trang trong moät öùng duïng. Thoâng tin chung ñöôïc caát giöõ trong Session laø nhöõng bieán nhö laø username vaø userid. - Moät Session coù theå baét ñaàu khi : . Ngöøôi duøng môùi yeâu caàu moät file .asp vaø thuû tuïc Session_Onstart ñöïôc ñaët trong file Global.asa . Moät giaù trò ñöôïc caát giöõ trong bieán Session . Ngöôøi duøng môùi yeâu caàu moät file .asp vaø Global.asa söû duïng tag ñeå khôûi taïo phaïm vi cuûa Session - Moät Session keát thuùc khi ngöøôi duøng yeâu caàu hoaëc laøm môùi laïi moät trang asp trong 1 khoaûng thôøi gian xaùc ñònh.Giaù trò naøy laø 20 phuùt theo maëc ñònh. - Thoâng thöôøng ngöôøi ta khôûi ñoäng caùc bieán thuoäc loaïi Session trong file global.asa .Vieäc taïo naøy ñöôïc thöïc hieän bôûi söï kieän Onstart - Caùch khai baùo bieán Session(“teân bieán ”) = giaù trò ; 2. Collections Contents Chöùa taát caû caùc thaønh phaàn ñöôïc theâm tôùi Session thoâng qua leänh script. StaticObjects Chöùa taát caû caùc object ñöôïc taïo bôûi theû vaø coù taàm vöïc laø Session. 3. Properties CodePage Thieát laäp baûng maõ ngoân ngöõ cho toaøn boä Session. LCID Thieát laäp chuaån ngaøy giôø cho Session. SessionID Traû veà moät soá ñònh nghóa cho moät keát noái. Timeout Löu thôøi gian laøm vieäc cuûa Session (ñôn vò tính laø phuùt). 4. Methods Abandon Keát thuùc moät Session. Huûy boû giaù trò hieän höõu cuûa caùc bieán Session Contents.Remove Xoaù moät thaønh phaàn cuûa taäp hôïp Content. Contents.RemoveAll Xoaù moïi thaønh phaàn cuûa taäp hôïp Content. 65
- 5. Events Session_OnStart Söï kieän naøy xuaát hieän moãi laàn khi ngööôøi duøng yeâu caàu trang ñaàu tieân trong öùng duïng ASP. Session_OnEnd Söï kieän naøy xuaát hieän moãi laàn khi ngööôøi duøng keát thuùc moät Session. Moät Session cuûa ngöøôI duøng ñuïôc keát thuùc sau khi trang asp khoâng ñöïôc yeâu caàutrong thôøi gian xaùc ñònh ( maëc ñònh naøy laø 20 phuùt). Moät Session cuõng keát thuùc khi ngööôøi duøng ñoùng trình duyeät hoaëc ñi tôùi trang cuûa website khaùc. Löu yù : Chuùng ta khoâng bieát lieäu yeâu caàu cuoái cuøng cuûa ngööôøi duøng laø keát thuùc hay khoâng. Vì theá chuùng ta khoâng bieát raèng Session coù chu kì soáng laø bao laâu => söû duïng quaù laâu caùc taøi nguyeân treân server .Nhöng neáu Session bò xoùa quaù nhanh maø chuùng ta muoán quay trôû laïi trong khi server ñaõ xoùa taát caû thoâng tin vì theá ngöøôi duøng phaûi baét ñaàu moät laàn nöõa. Do ñoù vieäc tìm khoaûng thôøi gian timeout coù theå khoù. Vì vaäy, neáu chuùng ta ñang söû duïng nhöõng bieán Session, khoâng neân löu tröõ soá löôïng döõ lieäu nhieàu trong chuùng. Boå sung : FILE GLOBAL.ASA a. Global.asa laø gì ? Trong Global.asa chuùng ta coù theå chæ roõ nhöõng script söï kieän vaø khai baùo nhöõng ñoái töôïng Session vaø Application maø coù theå ñöôïc truy nhaäp bôûi moãi trang Trong moät öùng duïng ASP. Global.asa coù theå chöùa noäi dung sau ñaây : . Nhöõng söï kieän Application . Nhöõng söï kieän Session . Khai baùo ñoái töïong . Khai baùo loaïi thö vieän Ghi chuù : Global.asa phaûi ñöôïc caát giöõ trong thö’muïc goác cuûa öùng duïng ASP vaø moãi öùng duïng chæ coù theå co’ moät file Global.asa . Nhöõng söï thay ñoåi trong Global.asa yeâu caàu khôûi ñoäng laïi cho server ñeå nhöõng thay ñoåi ñoù coù hieäu löïc. b. Nhöõng söï kieän chuaån trong Global.asa 66
- Trong Global.asa, chuùng ta coù theå noùi nhöõng ñoái töôïng Application vaø Session laøm caùi gì khi khôûi ñoäng Application / Session vaø phaûi laøm gì khi Application / Session keát thuùc. Caùc maõ naøy ñöôïc ñaët vaøo trong boä xöû lyù söï kieän. Global.asa coù theå chöùa ñöïng boán kieåu söï kieän laø : function Application_OnStart() { some javascript code } function Application_OnEnd() { some javascript code } function Session_OnStart() { some javascript code } function Session_OnEnd() { some javascript code } Ghi chuù: Chuùng ta khoâng söû duïng caùc nhoùm kyù töï “ ”, ñeå cheøn nhöõng maõ trong Global.asa maø chuùng ta phaûi ñaët nhöõng ñoaïn maõ beân trong theû c. Khai baùo Ngöôøi ta coù theå taïo ra phaïm vi nhöõng ñoái töôïng Session hoaëc Application trong Global.asa baèng vieäc söû duïng theû Theû naøy beân ngoaøI baát kyø theû naøo. Cuù phaùp : Tham soá Moâ taû scope Ñaët phaïm vi ñoái töïông( hoaëc Session hoaëc Application) 67
- id Chæ roõ moät teân cho ñoùi töïông ProgID Chæ roõ id lieân quan ñeán moät lôùp. ClassID Chæ roõ moät id duy nhaát cho moät ñoái töôïng lôùp COM. ProgID hoaëc ClassID phaûi ñöôïc chæ roõ. d. Khai baùo loaïi thö vieän Loaïi thö vieän nhö laø moät ‘container’ chöùa caùc file DLL tööông xöùng vôùi ñoái töôïng COM. Bôûi caùch goïi tôùi loaïi thö vieän trong GLOBAL.ASA nhöõng haèng soá ñoái töôïng ñoù coù theå ñöôïc truy nhaäp, vaø nhöõng loãi coù theå ñöôïc thoâng baùo toát hôn ñöôïc baùo caùo bôûi maõ ASP. Cuù phaùp : Tham soá Söï Moâ taû file Chæ roõ moät ñööôøng daãn tuyeät ñoái tôùi moät loaïi thö vieän uuid Chæ roõ moät ñònh danh duy nhaát cho loaïi thö vieän version Phieân baûn ñöôïc söû duïng ñeå choïn. Neáu phieân baûn ñöôïc yeâu caàu khoâng tìm thaáy, thì phieân baûn gaàn ñaây nhaát ñöôïc söû duïng localeid Tuøy choïn.Ñònh danh noäi boä seõ ñöôïc söû duïng cho loaïi thö vieän e.Loãi Giaù trò Server coù theå traû laïi cho moät thoâng baùo loãi nhö sau: Maõ loãi Söï Moâ taû ASP 0222 Ñònh danh loaïi thö vieän khoâng xaùc ñònh ASP 0223 Loaïi thö vieän khoâng tìm thaáy ASP 0224 Loaïi thö vieän khoâng theå taûi ASP 0225 Loaïi thö vieän khoâng theå nhuùng vaøo Ghi chuù : Theû c où theå xuaát hieän baát cöù nôi ñaâu ôû trong Global.asa ( Caû trong laãn beân ngoaøi tag ), tuy nhieân ngöôøi ta khuyeán caùo raèng theû neân xuaát hieän taïi ñænh cuûa file Global.asa f.Nhöõng haïn cheá 68
- Chuùng ta khoâng theå trình baøy vaên baûn ñöôïc trong Global.asa Taäp tin naøy khoâng theå trình baøy thoâng tin Chuùng ta khoâng theå söû duïng chæ thò trong Global.asa Trong Session_OnEnd, chuùng ta coù theå söû duïng Server, Application, vaø nhöõng ñoái töôïng Session. Trong chöông trình con Session_OnStart chuùng ta coù theå söû duïng baát kyø ñoái töôïng naøo coù saün 69
- III.Request Object 1. Taùc duïng Duøng ñeå laáy caùc thoâng tin töø browser göûi leân server. 2. Collections ClientCertificate Cung caáp caùc thoâng tin veà maùy client. Cookies Löu giöõ caùc giaù trò cookie göûi töø client leân server. Form Duøng ñeå truy xuaát nhöõng giaù trò trong moät Form vôùi phööông thöùc POST. Thoâng tin ñöôïc göûi baèng phöông thöùc POST thì User seõ khoâng nhìn thaáy. Phöông phaùp POST khoâng coù giôùi haïn, chuùng ta coù theå göûi raát nhieàu thoâng tin. QueryString Duøng ñeå truy xuaát nhöõng giaù trò trong moät Form vôùi phööông thöùc GET. Thoâng tin ñöôïc göûi baèng phöông thöùc GET thì User seõ nhìn thaáy thoâng tin trong URL. Phöông phaùp GET coù giôùi haïn, chuùng ta chæ coù theå göûi di moät URL coù chieàu daøi laø 256 bytes. ServerVariables The values of predetermined environment variables. 3. Properties TotalBytes Thuoäc tính chæ ñoïc, löu soá toång soá byte ñöôïc göûi töø client ñeán server. 4. Methods BinaryRead Nhaän döõ lieäu göûi töø browser leân server döôùi daïng nhò phaân. 70
- IV. Response Object 1. Taùc duïng : Ñoái töôïng Response thöôøng ñöôïc söû duïng ñeå göûi thoâng tin töø server ñeán caùc trình duyeät . 2. Collection : Collection Description Cookie Ñaët moät giaù trò cho cookie. Neáu cookie khoâng toàn taïi, noù seõ ñöôïc taïo môùi , vaø laáy giaù trò maø ñöôïc chæ roõ 3. Properties Tính chaát Söï Moâ taû Buffer Chæ roõ laø coù taïo ra boä ñeäm ñeå duyeät trang Web hay khoâng CacheControl Duøng ñeå xaùc ñònh xem proxy server coù theå naém baét caùc giaù trò xuaát ra bôûi caùc trang ASP hay khoâng Charset Caøi ñaët chuaån font cho trang ASP. ContentType Seõ gaùn caùc HTTP Content type cho ñoái töôïng Response Expires Xaùc ñònh trong khoaûng thôøi gian bao laâu thì trang Web ñoù seõ ñöôïc löu giöõ taïi client ExpiresAbsolute Ñaët ñònh ngaøy giôø khi moät trang löu giöõ taïi client seõ heát haïn IsClientConnected Xaùc ñònh xem client ñaõ ngaét ra khoûi server chöa Pics Gaén moät giaù trò cho PICS header Status Chæ roõ giaù trò cuûa traïng thaùi ñöôïc traû laïi bôûi server 4. Methods Method Description AddHeader Theâm moät tieâu ñeà HTTP môùi vaø moät giaù trò vaøo HTTP Response . AppendToLog Theâm moät chuoãi vaøo cuoái cuûa nhaät kyù server (log) . BinaryWrite Vieát döõ lieäu tröïc tieáp cho ñaàu ra maø khoâng coù baát kyø söï chuyeån ñoåi kí töï naøo Clear Laøm Saïch HTML Buffer End Ngöøng vieäc xöû lyù moät Script , vaø traû laïi keát quaû hieän haønh Flush Göûi HTML buffer ngay laäp töùc Redirect Chuyeån ngöôøi duøng tôùi moät URL khaùc nhau 71
- Write Vieát moät chuoãi ñöôïc chæ roõ cho ñaàu ra * Boå sung : COOKIE a. Cookie laø gì ? Web server khoâng bieát chuùng ta laø ai vaø ñang laøm gì bôûi vì ñòa chæ HTTP khoâng duy trì traïng thaùi. Ngöôøi ta giaûi quyeát vaán ñeà naøy baèng vieäc taïo ra moät cookie duy nhaát cho moãi ngöôøi duøng. Cookie ñöôïc göûi cho client vaø noù chöùa ñöïng thoâng tin giuùp nhaän daïng ngöôøi duøng. Cookie laø moät taäp tin côõ nhoû maø server nhuùng vaøo treân maùy tính cuûa ngööôøi duøng. Moãi khi maùy tính yeâu caàu moät trang Web thoâng qua trình duyeät, thì Server cuõng seõ göûi cookie ñeán maùy tính ñoù.Vôùi ASP, chuùng ta coù theå taïo ra cookie vaø laáy giaù trò cuûa cookie. b.Taïo cookie nhö theá naøo ? Caâu leänh Response.Cookies ñöôïc söû duïng ñeå taïo ra moät cookie : Ví duï : Trong ñoaïn code treân, chuùng ta ñaõ taïo ra moät cookie coù teân " firstname " vaø gaùn giaù trò " Alex " cho noù. c.Laáy giaù trò cookie nhö theá naøo ? Caâu leänh Request.Cookies ñöôïc söû duïng ñeå laáy giaù trò cuûa Cookies Ví duï : d. Moät cookie vôùi nhöõng khoaù Moät cookie coù theå cuõng chöùa ñöïng moät taäp hôïp nhieàu giaù trò. Chuùng ta noùi raèng cookie ñoù coù khoaù. Ví duï : e. Ñoïc taát caû caùc cookie 72
- Ngöôøi ta kieåm tra xem moät cookie coù khoaù vôùi tính chaát HasKeys. Ví duï : View cookie "); if(Request.Cookies(x).HasKeys) { for(y in Request.Cookies(x)) { Response.write(x + ":" + y + "=" + Request.Cookies(x)(y) ); Response.write(" ") ; } } else Response.Write(x +"="+ Request.Cookies(x) + " ") } Response.write(" "); %> Output: firstname=Alex user:firstname=John user:lastname=Smith user: country=Norway user: age=25 f.Neáu moät Trình duyeät khoâng hoã trôï cookie? Neáu öùng duïng cuûa chuùng ta gaëp phaûi nhöõng trình duyeät maø khoâng hoã trôï cookie, chuùng ta seõ phaûi söû duïng nhöõng phööông phaùp khaùc ñeå chuyeån thoâng tin töø trang naøy sang caùi khaùc trong öùng duïng cuûa chuùng ta. Coù hai caùch laøm ñieàu naøy : 1.Theâm nhöõng tham soá vaøo moät URL Ví duï : 73
- Vaø theâm nhöõng giaù trò nhaän ñöôïc vaøo trong taäp tin greeting.asp: Hello " + fname + " " + lname + "! "); Response.write(" Welcome to my Web site! "); %> 2. Söû duïng Form Ví duï : First Name: Last Name: Taïo laïi nhöõng giaù trò gioáng nhö sau (trong taäp tin greeting.asp) : Hello " + fname + " " + lname + "! ") ; Response.write(" Welcome to my Web site! "); %> 74
- V.Server Object 1.Taùc duïng Cung caáp söï truy caäp ñeán caùc thö vieän treân server 2.Properties ScriptTimeout Khoaûng thôøi gian toái ña maø script seõ ñöôïc xöû lyù. 3.Methods CreateObject Taïo moät caøi ñaët cuûa caùc component treân server. Execute Thi haønh moät file ASP. GetLastError Traû veà moät ASPError object dieãn taû ñieàu kieän loãi. HTMLEncode Maõ hoaù theo maõ HTML cho moät chuoãi. MapPath Traû veà moät ñöôøng daãn vaät lyù treân server. Transfer Göûi taát caû caùc tin töùc hieän thôøi ñeán moät file ASP khaùc. URLEncode Maõ hoaù theo maõ URL cho moät chuoãi. 75
- Caùc Component hoå trôï cho ASP VI. ADODB Object · ADO laø moät kyõ thuaät cuûa Microsoft · ADO vieát taét cuûa ActiveX Data Objects · ADO laø moät Microsoft Active-X component · ADO ñöôïc töï ñoäng caøi ñaët vôùi Microsoft IIS · ADO hoå trôï cho vieäc truy xuaát döõ lieäu trong CSDL · ADO coù theå ñöôïc truy xuaát töø trong trang ASP Caùc böôùc ñeå truy xuaát CSDL töø beân trong trang ASP: 1. Taïo moät ADO connection ñeán moät CSDL 2. Môû moät keát noái ñeán CSDL 3. Taïo moät ADO recordset 4. Môû moät recordset 5. Truy vaán vaø xöû lyù döõ lieäu 6. Ñoùng recordset 7. Ñoùng connection 1. Command Object Command object ñöôïc söû duïng ñeå thi haønh moät truy vaán ñôn giaûn treân CSDL. Truy vaán coù theå thi haønh caùc haønh ñoäng nhö taïo, theâm, ñoïc, xoaù vaø caäp nhaät caùc record trong CSDL. Ích lôïi chính cuûa Command object laø khaû naêng söû duïng caùc caâu truy vaán hay caùc SP trong CSDL. a. Khai baùo : var objCommand=Server.CreateObject("ADODB.command"); b. Properties: Property Description ActiveConnection Sets or returns a definition for a connection if the connection 76
- is closed, or the current Connection object if the connection is open CommandText Sets or returns a provider command CommandTimeout Sets or returns the number of seconds to wait while attempting to execute a command CommandType Sets or returns the type of a Command object Name Sets or returns the name of a Command object Prepared Sets or returns a Boolean value that, if set to True, indicates that the command should save a prepared version of the query before the first execution State Returns a value that describes if the Command object is open, closed, connecting, executing or retrieving data c. Methods Method Description Cancel Cancels an execution of a method CreateParameter Creates a new Parameter object Execute Executes the query, SQL statement or procedure in the CommandText property d. Collections Collection Description Parameters Contains all the Parameter objects of a Command Object Properties Contains all the Property objects of a Command Object 2. Connection Object Connection Object ñöôïc söû duïng ñeå taïo moät keát noái vôùi CSDL. Thoâng qua keát noái naøy, chuùng ta coù theå truy xuaát vaø thao taùc treân CSDL. a. Khai baùo : var objConnection=Server.CreateObject("ADODB.connection"); b. Properties : Property Description Attributes Sets or returns the attributes of a Connection object CommandTimeout Sets or returns the number of seconds to wait while 77
- attempting to execute a command ConnectionString Sets or returns the details used to create a connection to a data source ConnectionTimeout Sets or returns the number of seconds to wait for a connection to open CursorLocation Sets or returns the location of the cursor service DefaultDatabase Sets or returns the default database name IsolationLevel Sets or returns the isolation level Mode Sets or returns the provider access permission Provider Sets or returns the provider name State Returns a value describing if the connection is open or closed Version Returns the ADO version number c. Methods Method Description BeginTrans Begins a new transaction Cancel Cancels an execution Close Closes a connection CommitTrans Saves any changes and ends the current transaction Execute Executes a query, statement, procedure or provider specific text Open Opens a connection OpenSchema Returns schema information from the provider about the data source RollbackTrans Cancels any changes in the current transaction and ends the transaction d. Events Event Description BeginTransComplete Triggered after the BeginTrans operation CommitTransComplete Triggered after the CommitTrans operation ConnectComplete Triggered after a connection starts Disconnect Triggered after a connection ends ExecuteComplete Triggered after a command has finished executing 78
- InfoMessage Triggered if a warning occurs during a ConnectionEvent operation RollbackTransComplete Triggered after the RollbackTrans operation WillConnect Triggered before a connection starts WillExecute Triggered before a command is executed e. Collections Collection Description Errors Contains all the Error objects of the Connection object Properties Contains all the Property objects of the Connection object 3.Error Object Error object chöùa caùc chi tieát vaà loãi truy xuaát döõ lieäu maø ñöôïc taïo ra trong quaù trình thao taùc döõ lieäu. * Properties Property Description Description Returns an error description HelpContext Returns the context ID of a topic in the Microsoft Windows help system HelpFile Returns the full path of the help file in the Microsoft Windows help system NativeError Returns an error code from the provider or the data source Number Returns a unique number that identifies the error Source Returns the name of the object or application that generated the error SQLState Returns a 5-character SQL error code 4.Field Object Field object chöùa caùc tin töùc veà moät tröôøng (coät) trong moätRecordset object. a. Khai baùo var objField=Server.CreateObject("ADODB.field"); 79
- b. Properties Property Description ActualSize Returns the actual length of a field's value Attributes Sets or returns the attributes of a Field object DefinedSize Returns the defined size of a field Name Sets or returns the name of a Field object NumericScale Sets or returns the number of decimal places allowed for numeric values in a Field object OriginalValue Returns the original value of a field Precision Sets or returns the maximum number of digits allowed when representing numeric values in a Field object Status Returns the status of a Field object Type Sets or returns the type of a Field object UnderlyingValue Returns the current value of a field Value Sets or returns the value of a Field object c. Methods Method Description AppendChunk Appends long binary or character data to a Field object GetChunk Returns all or a part of the contents of a large text or binary data Field object d. Collections Collection Description Properties Contains all the Property objects for a Field object 5. Parameter Object Parameter object cung caáp caùc thoâng tin veà ñoái soá (parameter) söû duïng trong SP hay query. Coù 4 loaïi ñoái soá khaùc nhau : input parameters, output parameters, input/output parameters vaø return parameters. a. Properties Property Description Attributes Sets or returns the attributes of a Parameter object 80
- Direction Sets or returns how a parameter is passed to or from a procedure Name Sets or returns the name of a Parameter object NumericScale Sets or returns the number of digits stored to the right side of the decimal point for a numeric value of a Parameter object Precision Sets or returns the maximum number of digits allowed when representing numeric values in a Parameter Size Sets or returns the maximum size in bytes or characters of a value in a Parameter object Type Sets or returns the type of a Parameter object Value Sets or returns the value of a Parameter object b. Methods Method Description AppendChunk Appends long binary or character data to a Parameter object Delete Deletes an object from the Parameters Collection 6. Recordset Object Recordset object ñöôïc söû duïng ñeå söû lyù moät taäp caùc record truy vaán töø CSDL a. Khai baùo var objRecordset=Server.CreateObject("ADODB.recordset"); Recordset objects hoã trôï 2 loaïi caäp nhaät: · Immediate updating - taát caû nhöõng thay ñoåi ñöôïc vieát ngay laäp töùc ñeán CSDL khi chuùng ta goïi haøm Update(). · Batch updating - thöïc hieän nhöõng thay ñoåi trong cache vaø sau ñoù göûi taát caû ñeán CSDL baèng caùch goïi haøm UpdateBatch(). ADO ñònh nghóa 4 loaïi cursor : · Dynamic cursor - Cho pheùp ngöôøi söû duïng coù theå thaáy caùc thao taùc theâm, xoaù, söûa, ñöôïc thöïc hieän bôûi nhöõng user khaùc. · Keyset cursor - Töông töï nhö dynamic cursor nhöng user khoâng thaáy ñöôïc caùc thao taùc cuûa caùc user khaùc. 81
- · Static cursor - Phuïc vuï moät baûng copy tónh cuûa recordset nhaèm giuùp tìm kieám vaø taïo baùo caùo. · Forward-only cursor - Cho pheùp user chæ duyeät recordset theo moät chieàu. Thao taùc cuûa caùc user khaùc khoâng ñöôïc nhìn thaáy. b. Properties Property Description AbsolutePage Sets or returns a value that specifies the page number in the Recordset object AbsolutePosition Sets or returns a value that specifies the ordinal position of the current record in the Recordset object ActiveCommand Returns the Command object associated with the Recordset ActiveConnection Sets or returns a definition for a connection if the connection is closed, or the current Connection object if the connection is open BOF Returns true if the current record position is before the first record, otherwise false Bookmark Sets or returns a bookmark. The bookmark saves the position of the current record CacheSize Sets or returns the number of records that can be cached CursorLocation Sets or returns the location of the cursor service CursorType Sets or returns the cursor type of a Recordset object DataMember Sets or returns the name of the data member that will be retrieved from the object referenced by the DataSource property DataSource Specifies an object containing data to be represented as a Recordset object EditMode Returns the editing status of the current record EOF Returns true if the current record position is after the last record, otherwise false Filter Sets or returns a filter for the data in a Recordset object Index Sets or returns the name of the current index for a Recordset object LockType Sets or returns a value that specifies the type of locking when editing a record in a Recordset 82
- MarshalOptions Sets or returns a value that specifies which records are to be returned back to the server MaxRecords Sets or returns the maximum number of records to return to a Recordset object from a query PageCount Returns the number of pages with data in a Recordset object PageSize Sets or returns the maximum number of records allowed on a single page of a Recordset object RecordCount Returns the number of records in a Recordset object Sort Sets or returns the field names in the Recordset to sort on Source Sets a string value or a Command object reference, or returns a String value that indicates the data source of the Recordset object State Returns a value that describes if the Recordset object is open, closed, connecting, executing or retrieving data Status Returns the status of the current record with regard to batch updates or other bulk operations StayInSync Sets or returns whether the reference to the child records will change when the parent record position changes c. Methods Method Description AddNew Creates a new record Cancel Cancels an execution CancelBatch Cancels a batch update CancelUpdate Cancels changes made to a record of a Recordset object Clone Creates a duplicate of an existing Recordset Close Closes a Recordset CompareBookmarks Compares two bookmarks Delete Deletes a record or a group of records Find Searches for a record in a Recordset that satisfies a specified criteria GetRows Copies multiple records from a Recordset object into a two-dimensional array 83
- GetString Returns a Recordset as a string Move Moves the record pointer in a Recordset object MoveFirst Moves the record pointer to the first record MoveLast Moves the record pointer to the last record MoveNext Moves the record pointer to the next record MovePrevious Moves the record pointer to the previous record NextRecordset Clears the current Recordset object and returns the next Recordset object by looping through a series of commands Open Opens a database element that gives you access to records in a table, the results of a query, or to a saved Recordset Requery Updates the data in a Recordset by re-executing the query that made the original Recordset Resync Refreshes the data in the current Recordset from the original database Save Saves a Recordset object to a file or a Stream object Seek Searches the index of a Recordset to find a record that matches the specified values Supports Returns a boolean value that defines whether or not a Recordset object supports a specific type of functionality Update Saves all changes made to a single record in a Recordset object UpdateBatch Saves all changes in a Recordset to the database. Used when working in batch update mode d. Events Event Description EndOfRecordset Triggered when you try to move to a record after the last record FetchComplete Triggered after all records in an asynchronous operation have been fetched FetchProgress Triggered periodically in an asynchronous operation, to state how many more records that have been fetched FieldChangeComplete Triggered after the value of a Field object change 84
- MoveComplete Triggered after the current position in the Recordset has changed RecordChangeComplete Triggered after a record has changed RecordsetChangeComplete Triggered after the Recordset has changed WillChangeField Triggered before the value of a Field object change WillChangeRecord Triggered before a record change WillChangeRecordset Triggered before a Recordset change WillMove Triggered before the current position in the Recordset changes e. Collections Collection Description Fields Indicates the number of Field objects in the Recordset object Properties Contains all the Property objects in the Recordset object 85
- VII. FileSystemObject Object 1. FileSystemObject : FileSystemObject ñöôïc söû duïng ñeå truy caäp heä thoáng taäp tin treân server.Ñoái töôïng naøy coù theå thao taùc treân caùc taäp tin, thö muïc , vaø nhöõng ñööôøng daãn thö muïc. Ta coù theå laáy thoâng tin trong taäp tin heä thoáng vôùi ñoái tööôïng naøy. a. Properties Property Description Drives Traû veà moät taäp hôïp cuûa taát caû caùc ñoái tööôïng oå ñóa treân maùy tính b. Methods Method Description BuildPath Noái moät teân tôùi moät ñöôøng daãn hieän taïi CopyFile Sao cheùp töø moät hoaëc nhieàu taäp tin töø vò trí naøy sang vò trí khaùc CopyFolder Sao cheùp töø moät hoaëc nhieàu thö muïc töø vò trí naøy sang vò trí khaùc CreateFolder Taïo ra moät thö muïc môùi CreateTextFile Taïo ra moät taäp tin vaên baûn vaø traû veà moät ñoái töôïng TextStream maø ta coù theå söû duïng ñeå ñoïc ghi leân taäp tin DeleteFile Xoùa moät hoaëc nhieàu taäp tin DeleteFolder Xoùa moät hoaëc nhieàu thö muïc DriveExists Kieåm tra ñöôøng daãn coù toàn taïi hay khoâng FileExists Kieåm tra taäp tin coù toàn taïi hay khoâng FolderExists Kieåm tra thö muïc coù toàn taïi hay khoâng GetAbsolutePathName Traû veà toaøn boä ñööôøng daãn töø ñöôøng daãn goác cuûa noù GetBaseName Traû veà teân cuûa moät taäp tin ñöôïc chæ roõ hoaëc moät thö muïc GetDrive Traû veà moät ñoái töôïng oå ñóa töông öùng vôùi moät ñööôøng daãn ñöôïc chæ roõ GetDriveName Traû veà teân oå ñóa GetExtensionName Traû veà teân môû roäng cuûa taäp tin GetFile Traû veà moät ñoái tööôïng taäp tin GetFileName Traû veà cuûa moät taäp tin hoaëc thö muïc GetFolder Traû veà moät ñoái töôïng thö muïc GetParentFolderName Traû veà teân (cuûa)thö muïc cha GetSpecialFolder Traû veà ñööôøng daãn ñeám moät vaøI thö muïc ñaëc bieät . 86