Professional Documents
Culture Documents
Chương 2 : HTML
1
Nội dung
1. Giới thiệu chung về HTML
2. Trình bày văn bản trong HTML
3. Giới thiệu một số thẻ mới HTML5
4. Multimedia
5. Form trên trang web
6. IFrame
2
1. Giới thiệu chung – Định nghĩa
3
Lịch sử phát triển
HTML5 is about
semantics and devices
mobile web information
architecture/semantics
4
Foundations of HTML:
Open Web Technology Stack:
5
http://blog.smartbear.com/software-quality/bid/167272/Understanding-The-Open-Web-Stack
1. Giới thiệu chung – Đặc điểm
• HTML sử dụng các thẻ (tags) để định
dạng dữ liệu
• HTML không phân biệt chữ hoa, chữ
thường
• Các trình duyệt thường không báo lỗi cú
pháp HTML.
• Khi viết sai cú pháp thì trình duyệt sẽ hiển
thị không đúng với dự định.
• Có nhiều thẻ, mỗi thẻ có 1 tên và mang ý
6
nghĩa khác nhau.
1. Giới thiệu chung – Đặc điểm (tt)
• Một thẻ có thể có các thuộc tính nhằm bổ sung
tác dụng cho thẻ.
• Mỗi thuộc tính có tên thuộc tính (tên_TT)
• Viết thẻ có thuộc tính:
<tên_thẻ tên_TT1=“giá_trị1” tên_TT2=“giá_trị2”…>
• Chú ý:
– Có thể thay đổi thứ tự, số lượng các thuộc tính mà
không gây ra lỗi cú pháp.
– Sự hỗ trợ các thẻ, thuộc tính ở mỗi trình duyệt là
khác nhau. Chỉ giống nhau ở các thẻ, thuộc tính cơ
bản.
– Thẻ đóng của thẻ có thuộc tính vẫn viết bình thường
(</tên_thẻ>)
1. Giới thiệu chung – Đặc điểm (tt)
• Có 2 loại thẻ: thẻ đóng và thẻ mở
• Cách viết thẻ:
– Thẻ mở: <tên_thẻ>
Ví dụ: <u>, <p>, <img>…
– Thẻ đóng tương ứng: </tên_thẻ>
Ví dụ: </u>, </p>
Chú ý:
• Luôn có thẻ mở nhưng có thể không có thẻ đóng
tương ứng. Ví dụ: <img> không có thẻ đóng
• Các thẻ có thể lồng nhau, nhưng không đan xen
lẫn nhau. 8
Ví dụ
1. Giới thiệu chung – Đặc điểm (tt)
• Tập tin HTML có phần mở rộng (đuôi) là
.HTM hoặc .HTML là tập tin thuần văn bản
(plain text)
• Có thể soạn thảo file HTML bằng bất cứ
trình soạn thảo “văn bản thuần” nào
(Notepad, EditPlus, Notepad++, …)
• Trình hỗ trợ soạn thảo HTML (trực quan,
code):
– Adobe Dreamweaver CS6
–…
10
11
2. TRÌNH BÀY TÀI LIỆU TRONG HTML
13
2.1. Thẻ thể hiện cấu trúc tài liệu
• <html></html>: Định nghĩa phạm vi của
văn bản HTML
• <head></head>: Định nghĩa các mô tả về
trang HTML. Thông tin trong tag này không
được hiển thị trên trang web
• <title></title>: Mô tả tiêu đề trang web
• <body></body>: Xác định vùng thân của
trang web, nơi chứa các thông tin
14
HTML5 Doctype
• Dùng để chỉ rõ tài liệu theo chuẩn gì
(HTML5/XHTML5)
<!DOCTYPE html>
15
2.2. Thẻ META
• Đặt ở giữa <head>…</head>
• Thường dùng quy định thuộc tính cho
trang web
• Có tác dụng lớn với Search Engine
• Có 2 cách viết thẻ <meta>:
<META NAME="name" CONTENT="content">
<META HTTP-EQUIV="name"
CONTENT="content">
16
2.2. Thẻ META
Một số thẻ Meta thông dụng
• <META charset="utf-8">
• <META NAME="description" content="">
• <META NAME="keywords" content="">
• <META NAME="author" CONTENT="author's
name">
• <META HTTP-EQUIV="refresh"
CONTENT="delay;url=new url">
Link: http://www.w3schools.com/tags/tag_meta.asp 17
2.2. Thẻ META
Tự động chuyển hướng trang web
18
2.3. Thẻ định dạng khối tài liệu
Thẻ <DIV> được sử dụng để
DIV
đóng khối văn bản.
Thẻ <P> được sử dụng để định
P
dạng một đoạn văn bản.
Xác định 1 trong 6 cấp của tựa
H1,H2,H3,…,H6
đề (heading)
BR Ngắt dòng
Văn bản nằm trong thẻ này sẽ
PRE được trình bày như nguyên thủy
của nó khi gõ vào. 19
2.4. Thẻ định dạng danh sách
• OL
<OL TYPE=1/a/A/i/I>
– Danh sách được sắp xếp thứ <li>Mục 1</li>
tự <li>Mục 2</li>
– Hỗ trợ thuộc tính start cho <li>Mục 3</li>
phép chọn giá trị khởi đầu </OL>
• UL
– Danh sách không sắp xếp
<UL>
– Thẻ <LI> có thuộc tính TYPE <li>Mục 1</li>
có các giá trị <li>Mục 2</li>
• disc (chấm tròn đậm); <li>Mục 3</li>
• circle (vòng tròn); </UL>
• square (hình vuông) 21
2.4. Thẻ định dạng danh sách
22
2.4. Thẻ định dạng danh sách
23
2.5. Thẻ định dạng ký tự
<B></B>
In chữ đậm
<STRONG></STRONG>
<I></I><EM></EM> In chữ nghiêng
<U></U> In chữ gạch chân
<S></S><STRIKE></STRIKE> In chữ bị gạch ngang.
In chữ lớn hơn kích thước font hiện thời lên
một. Các thẻ <BIG> lồng nhau tạo ra hiệu ứng
chữ tăng dần. Đối với mỗi trình duyệt có giới
<BIG> ... </BIG> hạn về kích thước đối với mỗi font chữ, vượt
quá giới hạn này, các thẻ <BIG> sẽ không có ý
nghĩa.
In chữ nhỏ hơn bình thường bằng cách giảm
<SMALL> ... </SMALL> kích thước font hiện thời đi một. Tương tự như
thẻ BIG
<SUP> ... </SUP> Định dạng chỉ số trên (SuperScript)
<SUB> ... </SUB> Định dạng chỉ số dưới (SubScript) 24
2.6. Liên kết
• Thuộc tính:
– href=“đích liên kết”: Nếu trong cùng web nên sử dụng
đường dẫn tương đối.
– target=“tên cửa sổ đích”, tên cửa sổ phân biệt chữ
hoa/thường
• name: tải trang web vào frame có tên name
• _blank: tải trang web vào cửa sổ mới
• _parent: tải trang web vào cửa sổ cha của nó
• _self: tải trang web vào chính cửa sổ hiện hành
• _top: tải trang web vào cửa số cao nhất
25
2.6. Liên kết (tt)
• Lưu ý:
– Liên kết với địa chỉ e-mail thì đặt
href=“mailto:địa_chỉ_e-mail”
– Thực hiện lệnh JavaScript khi kích chuột vào thì đặt
href=“javascript:lệnh”
• Liên kết đến trang khác
– Thuộc tính href=“url của trang khác”
– Khi click vào liên kết sẽ chuyển đến trang khác
• Liên kết trong cùng một trang
– Thuộc tính href=“#id của thẻ trong trang”
– Khi click và liên kết sẽ chuyến đến thẻ có “id” được
ghi trong thuộc tính id của thẻ. 26
2.6. Liên kết (tt)
27
2.7 Bảng - Cấu trúc của 1 bảng
28
2.7 Bảng (tt)
STT Tên thẻ Mô tả - Ví dụ
1 <table>…</table> Khởi tạo 1 bảng
2 <tr>…</tr> Tạo 1 dòng (thẻ <tr> phải nằm trong
thẻ <table>)
3 <th>…<th> Tạo 1 ô tiêu đề (thẻ <th> phải nằm
trong thẻ <tr>)
4 <td>…</td> Tạo 1 ô dữ liệu (thẻ <td> phải nằm
trong thẻ <tr>)
34
Structure
35
Structure
HTML5 offers new semantic elements to define different parts of a
web page:
• <article>
• <aside>
• <details>
• <figcaption>
• <figure>
• <footer>
• <header>
• <main>
• <mark>
• <nav>
• <section>
• <summary> 36
• <time>
<section>
• The section element represents a generic
section of a document or application. A section,
in this context, is a thematic grouping of content,
typically with a heading
37
<header>
• A header element is intended to usually contain
the section's heading (an h1–h6 element or an
hgroup element), but this is not required. The
header element can also be used to wrap a
section's table of contents, a search form, or any
relevant logos
38
<hgroup>
• The hgroup element represents the heading of a
section. The element is used to group a set of
h1–h6 elements when the heading has multiple
levels, such as subheadings, alternative titles, or
taglines
39
<footer>
• The footer element represents a footer for its
nearest ancestor sectioning content or
sectioning root element. A footer typically
contains information about its section such as
who wrote it, links to related documents,
copyright data, and the like
40
<article>
• The article element represents a self-contained
composition in a document, page, application, or site and
that is, in principle, independently distributable or
reusable, e.g. in syndication. This could be a forum post,
a magazine or newspaper article, a blog entry, a user-
submitted comment, an interactive widget or gadget, or
any other independent item of content..
41
<nav>
• The nav element represents a section of a page
that links to other pages or to parts within the
page: a section with navigation links
42
Block semantic element
• <aside>
• <figure>
43
<aside>
• The aside element represents a section of a
page that consists of content that is tangentially
related to the content around the aside element,
and which could be considered separate from
that content. Such sections are often
represented as sidebars in printed typography.
44
<figure>
• Specifies self-contained content, like
illustrations, diagrams, photos, code listings, etc
45
Inline semantic element
• <mark>
• <time>
• <meter>
• <progress>
46
<mark>
• Defines marked/highlighted text
47
<time>
• Defines a date/time
48
<meter>
• Defines a scalar measurement within a known
range (a gauge)
49
<progress>
• The progress element provides a simple and
effective way for a web designer to notify a user
of their progress regarding a specified task
4. Multimedia
4.1 Hình ảnh
4.2 Âm thanh
4.3 Video
4.4 Plugin
4.5 Video
51
4.1. Hình ảnh
• <img> : Không có thẻ đóng
• Các thuộc tính của tag <img>:
– align: left, right, center
– src : Đường dẫn đến file hình ảnh
– alt : Chú thích cho hình ảnh
– position: Top, Bottom, Middle
– border : Độ dày nét viền quanh ảnh (default=0)
– width: độ rộng
– height: độ cao
• Đặt ảnh nền cho trang web
– <body background=‘Image Path’>
52
4.2 HTML5 Audio
• Example:
<audio src="foo.wav" controls autoplay>
Your browser does not support the <audio>
element.
</audio>
• Property:
– src, autoplay, controls
– loop, autobuffer, preload, muted
53
4.2 HTML5 Audio - Media Types
54
Example
<audio id="audio" controls>
<source src="orion.ogg" type="audio/ogg" />
<source src="music.mp3" />
</audio>
55
4.3 HTML5 Video
• Example:
<video src="foo.mp4" width="300" height="200" controls>
Your browser does not support the <video> element.
</video>
• Property:
– src, autoplay, controls, height, width,
– loop, autobuffer, preload, poster
56
Handling Media Events
Event Description
abort This event is generated when playback is aborted.
canplay This event is generated when enough data is
available that the media can be played.
ended This event is generated when playback completes.
error This event is generated when an error occurs.
loadeddata This event is generated when the first frame of
the media has finished loading.
loadstart This event is generated when loading of the media
begins.
57
Handling Media Events
Event Description
pause This event is generated when playback is paused.
play This event is generated when playback starts or
resumes.
progress This event is generated periodically to inform the
progress of the downloading the media.
ratechange This event is generated when the playback speed
changes.
seeked This event is generated when a seek operation
completes.
58
Handling Media Events
Event Description
seeking This event is generated when a seek operation
begins.
suspend This event is generated when loading of the
media is suspended.
volumechange This event is generated when the audio volume
changes.
waiting This event is generated when the requested
operation (such as playback) is delayed
pending the completion of another operation
(such as a seek).
59
4.4 HTML Plug-ins
• Sử dụng <object> : hỗ trợ bởi tất cả
browser
• Ví dụ:
– <object width="400" height="50"
data="bookmark.swf"></object>
– <object width="100%" height="500px"
data="snippet.html"></object>
– <object data="audi.jpeg"></object>
60
4.4 HTML Plug-ins (tt)
• Sử dụng <embed> : chỉ được hỗ trợ bởi
một số browser.
• Ví dụ:
– <embed width="400" height="50"
src="bookmark.swf">
– <embed width="100%" height="500px"
src="snippet.html">
– <embed src="audi.jpeg">
61
4.5 YouTube
• Right click YT, chọn “Copy embed
code/Sao chép mã nhúng”
62
5. FORM TRONG TRANG WEB
63
5.1. Giới thiệu về Form
• Được dùng để nhận dữ liệu từ phía người dùng
• Giúp gởi yêu cầu của người dùng đến trang xử
lý trong ứng dụng web
• Tag <form> dùng để chứa các thành phần khác
của form
• Những thành phần nhập liệu được gọi là Form
Field
– text field
– password field
– multiple-line text field
– …… 64
5.1. Giới thiệu về Form
<form name=“..” action=“…” method=“POST/GET”>
<!-- Các thành phần của form-->
</form>
• Là container chứa các thành phần nhập liệu khác.
• Các thuộc tính của <form>
– name: tên FORM
– action: chỉ định trang web nhận xử lý dữ liệu từ FORM
này khi có sự kiện click của button SUBMIT.
– method: Xác định phương thức chuyển dữ liệu (POST,
GET)
65
5.1. Giới thiệu về Form
Dangnhap.html
<html>
<body>
<form Name=“Dangnhap”
Action=“./admin/xlDangnhap.php”
Method=“POST” >
………………
</form>
</body>
</html>
66
5.2. Các thành phần của Form
■ button ■ checkbox ■ file ■ hidden ■ image ■ password ■ radio ■ reset ■ submit ■ text
68
5.2. Thành phần của Form – Text field
• Dùng để nhập một dòng văn bản
• Ví dụ:
72
5.2. Thành phần của Form – Pull-down
<Select name=“…”>
<optgroup label=“…”>
<option [selected] value=“…” >……</option>
………
</optgroup>
<option [selected] value=“…” >……</option>
………
</select>
Xem code
ở slide tiếp
73
5.2. Thành phần của Form – Combo box
List box:
Select software: <select multiple>
<select name="DSSoftware">
<optgroup label="Multimedia">
<option value="WM">Window Media</option>
<option value=“KMP">KMPlayer</option>
</optgroup>
<optgroup label="Operation System">
<option value="W7">Windows 7</option>
<option value="W8">Windows 8.1</option>
<option value="W10">Windows 10</option>
</optgroup>
<option selected value="Office15">Office 2015</option>
</select> 74
5.2. Thành phần của Form – Checkbox
<input
type = “checkbox”
name = “…”
value = “…”
[checked]
>
75
5.2. Thành phần của Form – Radio
<input
type = “radio”
name = “…”
value = “…”
[checked]
> Lưu ý: trường hợp hai radio
không cùng tên.
Chọn giới tính : <br>
Nam: <input type="radio" name=“gt" value="nam" checked><br>
Nữ: <input type="radio" name=“gt" value="nữ"><br>
76
5.2. Thành phần của Form – File
• Sử dụng để upload file lên server
<html>
<body>
<form name=“frmMain” method=“POST” enctype=“multipart/form-data”
action=“xuly.php”>
<input type="file" name="fileUpload“><br>
<input type=“submit” value=“send”><br>
<input type=“reset” value=“reset”>
</form>
</body>
</html> 79
5.2. Thành phần của Form – Button
80
5.2. Thành phần của Form – Button
81
5.2. Thành phần của Form – LABEL
Thành phần không bắt buộc, tăng khả năng truy cập cho form.
<label for="txtPhone">Phone</label>
<input type="text" name="txtPhone" id="txtPhone">
82
5.2. Thành phần của Form – Fieldset
<fieldset>
<legend> Subject </legend>
<input type="checkbox" name="Subject[ ]" value="Eng"> English<br>
<input type="checkbox" name="Subject[ ]" value="Math" checked>Mathematics<br>
<input type="checkbox" name="Subject[ ]" value="GraphTheory">Graph Theory
</fieldset>
83
5.3 Một số thuộc tính mới
• Của thẻ <form>: autocomplete, novalidate
• Của thẻ <input>:
– autocomplete – height and width
– autofocus – list
– form – min and max
– formaction – multiple
– formenctype – pattern (regexp)
– formmethod – placeholder
– formnovalidate – required
– formtarget – step
84
Search
<input type> search
Search Google:
<input type="search" name="googlesearch" />
85
Email
<input type> email
86
URL
<input type> url
Dùng để nhập liệu địa chỉ web (URL address).
Field sẽ được tự động validate khi form submit.
Hỗ trợ bởi Chrome, Opera, firefox.
87
Range
<input type> range
Hỗ trợ Opera và WebKit (Chrome). Gồm có các
thuộc tính min, max, và step.
Dùng hỗ trợ validate nhập liệu số.
88
Sliders
<form>
<input type="range" min="0" max="20" step="2"
value="2">
<input type=“submit” value=“Go”>
</form>
89
color
<input type> color
The color input type (type="color") provides the
user with a color picker Supported only in Opera,
Chrome
Select your favorite color:
<input type="color" name="favcolor" />
90
Spin Boxes
<form>
<input type="number" min="0" max="20" step="2"
value="2">
</form>
91
Date Pickers
<form>
<input type="date">
<input type="datetime">
<input type="datetime-local">
<input type=“time">
<input type="week">
<input type="month">
<input type="submit">
</form>
92
Data Lists
<form>
<input type=“text” list=“states”>
<datalist id=“states” >
<option value=“AK” label=“Alaska”>
<option value=“AL” label=“Alabama”>
<option value=“AR” label=“Arkansas”>
</datalist>
</form>
93
Datalist (tt)
<datalist id="frameworks">
<option value="MooTools">
<option value="Moobile">
<option value="Dojo Toolkit">
<option value="jQuery">
<option value="YUI">
</datalist>
94
keygen
<input type> keygen
The purpose of the <keygen> element is to provide a secure
way to authenticate users.
The <keygen> tag specifies a key-pair generator field in a
form. When the form is submitted, two keys are generated,
one private and one public.
The private key is stored locally, and the public key is sent
to the server. The public key could be used to generate a
client certificate to authenticate the user in the future.
<form action="demo_keygen.asp" method="get">
Username: <input type="text" name="usr_name" />
Encryption: <keygen name="security" />
<input type="submit" />
</form>
95
output
<input type> output
<form
oninput="x.value=parseInt(a.value)+parseInt(b.value)">0
<input type="range" name="a" value="50" />100
+<input type="number" name="b" value="50" />
=<output name="x" for="a b"></output>
</form>
96
HTML5 Form Attribute Enhancements
• Các thuộc tính mới autofocus, required,
placeholder, maxlength, và pattern. Trong
đó required và placeholder sử dụng cho
textbox.
<form>
<input name="q" placeholder=“Search Text">
<input type="submit" value="Search">
</form>
97
5.4. Gởi dữ liệu bằng POST/GET
<html>
<body>
<form method=“GET” action=“xuly.php”>
Anh văn: <input type="checkbox" name=“L1" value="En"><br>
Hoa: <input type="checkbox" name=“L2" value="Chz" checked><br>
Nhật: <input type="checkbox" name=“L3" value="Jp"><br>
<input type=“submit" value=“send">
</form>
</body>
</html>
GET
99
5.4. Gởi dữ liệu bằng POST/GET
POST 101
6. Khung (iframe)
102
6. Khung (iframe) (tt)
• Tạo trang web chứa các khung và chèn:
<iframe src="URL"></iframe>
• Một số thuộc tính của <iframe>
– height and width
<iframe src="demo_iframe.htm" width="200"
height="200"></iframe>
– Remove the Border: style="border:none"
<iframe src="demo_iframe.htm" style="border:none"></iframe>
– Use iframe as a Target for a Link
<iframe src="demo_iframe.htm" name="iframe_a"></iframe>
<p><a href=“abc.html“ target="iframe_a">ABC</a></p> 103
Bài tập tự làm
W3School HTML Exercise:
• http://www.w3schools.com/html/exercise.asp
104
Câu hỏi và thảo luận
105
Thảo luận
( ?)
0
Thảo luận
a. URL?
c. Web editor?
Thảo luận
▪ Họ tên:
▪ Mã SV:
▪ Lớp:
▪ Khoá:
▪ Email:
▪ Số ĐT:
▪ Kỹ năng lập trình:
▪ Dự án web đã làm:
01 02 … 19 20