Introduction to HTML5: Part 2مقدمة في HTML5: الجزء الثاني

الشريحة 1 من 19

مقدمة الفصل

ماذا ستتعلم في هذا الفصل

  1. Build a form using the new HTML5 input types.
  2. Specify an input element in a form as the one that should receive the focus by default.
  3. Use self-validating input elements.
  4. Specify temporary placeholder text in various input elements.
  5. Use autocomplete input elements that help users reenter text that they've previously entered in a form.
  6. Use a datalist to specify a list of values that can be entered in an input element and to autocomplete entries as the user types.
  7. Use HTML5's new page structure elements to delineate parts of a page, including headers, sections, figures, articles, footers and more.
تفاصيل المصدرالفصل 3 · الشرائح ⁦3–4⁩
المصدر
الفصل 3 · الشرائح ⁦3–4⁩

New input types: color and autofocusالنوع color و autofocus

Fig. 3.1 demonstrates HTML5's new form input types. These are not yet universally supported by all browsers.

input type="color"
Enables the user to enter a color. At the time of writing, most browsers render it as a text field for a hexadecimal code or a color name.
autofocus attribute
An optional attribute that can be used in only one input element on a form. It automatically gives the focus to that element, allowing the user to begin typing immediately.
تفاصيل المصدرالفصل 3 · الشرائح ⁦6, 12, 13⁩
المصدر
الفصل 3 · الشرائح ⁦6, 12, 13⁩

Self-validating inputsالتحقق الذاتي

Self-validating input types

The new input types are self validating on the client side:

  • No need to add complicated JavaScript code to validate user input.
  • Reduces the amount of invalid data submitted.
  • Consequently reduces Internet traffic between the server and the client to correct invalid input.
formnovalidate
Added to the submit input to bypass validation: <input type = "submit" value = "Submit" formnovalidate />
تفاصيل المصدرالفصل 3 · الشرائح ⁦15, 18⁩
المصدر
الفصل 3 · الشرائح ⁦15, 18⁩

سؤال سريع

Self-validating input types

A developer says: "HTML5 inputs validate themselves, so my server code no longer needs to check the data." Which reply is correct?

تفاصيل المصدرالفصل 3 · الشريحة ⁦15⁩
المصدر
الفصل 3 · الشريحة ⁦15⁩

Date and time input typesأنواع التاريخ والوقت

Input typeالنوعWhat the user entersما يُدخلFormat given on the slidesالصيغة في الشرائح
dateA dateyyyy-mm-dd (e.g., 2012-01-27)
datetimeDate, time and time zone set to UTCFig. 3.1 hint: yyyy-mm-ddThh:mm+ff:gg, such as 2012-01-27T03:15
datetime-localDate and time in a single controlFig. 3.1 hint: yyyy-mm-ddThh:mm, such as 2012-01-27T03:15
monthYear and monthyyyy-mm (e.g., 2012-01)
timeHour, minute, seconds, fraction of a secondhh:mm, optionally :ss and .fraction
weekYear and week numberyyyy-Wnn, nn = 01–53 (e.g., 2012-W01)
تفاصيل المصدرالفصل 3 · الشرائح ⁦19, 21, 22, 29, 38, 40⁩
المصدر
الفصل 3 · الشرائح ⁦19, 21, 22, 29, 38, 40⁩
ملاحظات حول المصدر (1)
  • صيغ datetime و datetime-local مأخوذة من نص التلميح في الشكل 3.1، لأن جدول الصيغ (الشكل 3.5) غير موجود في الملف.

email, placeholder and requiredemail و placeholder و required

input type="email"
Enter an e-mail address (or a comma-separated list with the multiple attribute). HTML5 does not check whether the address actually exists — only that it is in the proper format.
placeholder
Temporary text (generally light gray) showing an example of what to enter. It disappears when the focus is placed in the field and is not submitted.
  • placeholder is supported for only six input types: text, search, url, tel, email and password.
required
Forces the user to enter a value before submitting the form. It can be added to any input type.
تفاصيل المصدرالفصل 3 · الشرائح ⁦23, 25, 27⁩
المصدر
الفصل 3 · الشرائح ⁦23, 25, 27⁩

سؤال سريع

email, placeholder and required

Which input best matches: "an e-mail field that must be filled in and shows grey sample text that disappears when the user clicks in it"?

تفاصيل المصدرالفصل 3 · الشرائح ⁦23, 25, 27⁩
المصدر
الفصل 3 · الشرائح ⁦23, 25, 27⁩

number and rangenumber و range

input type="number"
Enter a numerical value (mobile browsers show a numeric keypad). min = minimum valid number, max = maximum, step = increment, value = initial value.
input type="range"
Appears as a slider control. You can set the minimum and maximum and specify a value.
  • range is inherently self-validating as a slider: the user cannot move the slider outside the minimum or maximum.

من الشرائح

  • <input type = "number" min = "0" max = "7" step = "1" value = "4" />
  • <input type = "range" min = "0" max = "20" value = "10" />
تفاصيل المصدرالفصل 3 · الشرائح ⁦9, 30, 33⁩
المصدر
الفصل 3 · الشرائح ⁦9, 30, 33⁩

سؤال سريع

number and range

A "rate this course" control must let the user drag a handle to choose any whole number from 0 to 10, starting at 5. Which markup fits?

تفاصيل المصدرالفصل 3 · الشريحة ⁦33⁩
المصدر
الفصل 3 · الشريحة ⁦33⁩

search, tel and urlsearch و tel و url

input type="search"
A search field for a query; functionally equivalent to an input of type text.
input type="tel"
Enter a telephone number. HTML5 does not self validate tel; the example adds a pattern attribute with a regular expression for the format (555) 555-5555.
input type="url"
Enter a URL; the proper format is http://www.deitel.com. www.deitel.com or www.deitelcom will not validate. Only the format is checked.

من الشرائح

  • Fig. 3.1 (slide 10): <input type = "search" placeholder = "search query" /> — Fig. 3.13 shows entering a search query in Chrome.
  • <input type = "tel" placeholder = "(###) ###-####" pattern = "(d{3}) +d{3}-d{4}" required /> — Fig. 3.14: validating a phone number using the pattern attribute ("Please match the requested format.").
  • <input type = "time" /> (hh:mm:ss.ff) — Fig. 3.15: time input as rendered in Chrome.
  • <input type = "url" placeholder = "http://www.domainname.com" /> — Fig. 3.16: validating a URL in Chrome ("Please enter a URL.").
  • Slide 11: <input type = "week" /> (yyyy-Wnn, such as 2012-W01); <input type = "submit" value = "Submit" />; <input type = "reset" value = "Clear" />.
تفاصيل المصدرالفصل 3 · الشرائح ⁦10, 11, 35, 36, 39⁩
المصدر
الفصل 3 · الشرائح ⁦10, 11, 35, 36, 39⁩

سؤال سريع

search, tel and url

A form uses <input type = "tel">. A user types "hello" and submits. Which extra attribute is needed so that a wrong format is rejected?

تفاصيل المصدرالفصل 3 · الشريحة ⁦36⁩
المصدر
الفصل 3 · الشريحة ⁦36⁩

autocomplete and datalistautocomplete و datalist

autocomplete attribute
Automatically fills in the user's information based on previous input — such as name, address or e-mail. It can be enabled for an entire form or specific elements.

من الشرائح

  • An online order form might set autocomplete = "on" for name and address, and autocomplete = "off" for the credit card and password inputs for security purposes.
datalist element
Provides input options for a text input element. The input's list attribute names the datalist's id.

من الشرائح

  • <input type = "text" id = "txtList" list = "months" /> <datalist id = "months"> <option value = "January"> … </datalist>
تفاصيل المصدرالفصل 3 · الشرائح ⁦43, 48, 49⁩
المصدر
الفصل 3 · الشرائح ⁦43, 48, 49⁩

سؤال سريع

autocomplete and datalist

Which markup correctly connects a text input to a list of suggested cities?

تفاصيل المصدرالفصل 3 · الشرائح ⁦43, 49⁩
المصدر
الفصل 3 · الشرائح ⁦43, 49⁩

Page-structure elements (1)عناصر البنية (1)

Page-structure elements: header, time, nav, figure, article

HTML5 introduces new page-structure elements that meaningfully identify areas of the page as headers, footers, articles, navigation areas, asides, figures and more.

header
A header for the page containing text and graphics; can be used multiple times and can include headings, navigation, images and logos.
time
Identifies a date, a time or both (need not be inside a header).
nav
Groups navigation links.
figure / figcaption
figure describes a figure (image, chart or table) so it could be moved to the side or another page; figcaption gives its caption.
article
Standalone content that could be used or distributed elsewhere (news article, forum post, blog entry). Articles can be nested.
تفاصيل المصدرالفصل 3 · الشرائح ⁦50, 64, 65, 66, 67⁩
المصدر
الفصل 3 · الشرائح ⁦50, 64, 65, 66, 67⁩

Page-structure elements (2)عناصر البنية (2)

Page-structure elements: summary/details, section, aside, meter, footer, mark, wbr

summary / details
summary displays a right-pointing arrow next to a summary or caption; when clicked, the arrow points downward and reveals the content in details.
section
A section of a document, usually with a heading; sections can be nested, also inside an article.
aside
Content related to the surrounding content but somewhat separate from the flow of the text (e.g., background history in a news story).
meter
A visual representation of a measure within a range (e.g., min "0", max "54", value "14").
footer
Content that usually appears at the bottom of the content or section (e.g., copyright notice and contact information).
mark
Highlights the text enclosed in the element.
wbr
Indicates the appropriate place to break a word when text wraps to multiple lines.
تفاصيل المصدرالفصل 3 · الشرائح ⁦68, 70, 71, 72, 74, 75⁩
المصدر
الفصل 3 · الشرائح ⁦68, 70, 71, 72, 74, 75⁩

سؤال سريع

Page-structure elements: summary/details, section, aside, meter, footer, mark, wbr

An FAQ page shows each question with a small arrow; clicking the arrow reveals the answer. Which elements fit this?

تفاصيل المصدرالفصل 3 · الشريحة ⁦68⁩
المصدر
الفصل 3 · الشريحة ⁦68⁩

All page-structure elementsجدول عناصر البنية

Page-structure elements: summary/details, section, aside, meter, footer, mark, wbr

ElementالعنصرWhat it does (slides)وظيفته في الشرائح
header
  • A header for the page (text and graphics)
  • can be used multiple times
timeIdentifies a date, a time or both
navGroups navigation links
figure / figcaptionA figure that could be moved elsewhere / its caption
article
  • Standalone content (news article, forum post, blog entry)
  • can be nested
summary / details
  • Right-pointing arrow
  • clicking reveals the details content
section
  • A section of a document, usually with a heading
  • can be nested
asideRelated content somewhat separate from the flow of the text
meterVisual representation of a measure within a range
footerContent at the bottom of the content or section (e.g., copyright, contact)
markHighlights the enclosed text
wbrWhere to break a word when text wraps

Fig. 3.18 — the whole example page (slides 51–63)

  • a) A header element containing a nav element with an unordered list of links (the Recent Publications book list) — slides 52, 59.
  • b) A section containing a figure (the Java How to Program cover) and a figcaption — slides 53, 60.
  • c) An article containing a header, content with marked (highlighted) text, a collapsed details element with a summary ("Recent Edition Testimonials"), followed by an aside element ("The aside element is not formatted by the browsers.") — slides 53–56, 61.
  • d) The end of the section that started in part (b): Deitel Developer Series Books and LiveLessons Videos — slides 57, 62.
  • e) The last section containing a meter element (<meter min = "0" max = "54" value = "14"></meter> — of the 54 responders, 14 would prefer to learn Java in the context of Android app development), followed by a footer element with a wbr element (where to break a word when the text wraps) and an address element (a mailto link) — slides 57–58, 63.
تفاصيل المصدرالفصل 3 · الشرائح ⁦51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 70, 71, 72, 74, 75⁩
المصدر
الفصل 3 · الشرائح ⁦51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 70, 71, 72, 74, 75⁩

سؤال سريع

Page-structure elements: header, time, nav, figure, article

A news site shows a story with a side box giving background history related to the story. Which pair of elements fits?

تفاصيل المصدرالفصل 3 · الشرائح ⁦67, 71⁩
المصدر
الفصل 3 · الشرائح ⁦67, 71⁩

الخلاصة

تفاصيل المصدر
المصدر
الفصل 3

خريطة الفصل

    1. 1مقدمة الفصل
    1. 2New input types: color and autofocusالنوع color و autofocus
  1. Self-validating input typesالتحقق الذاتي

    1. 3Self-validating inputsالتحقق الذاتي
    2. 4سؤال سريع: التحقق
    1. 5Date and time input typesأنواع التاريخ والوقت
  2. email, placeholder and requiredemail و placeholder و required

    1. 6email, placeholder and requiredemail و placeholder و required
    2. 7سؤال سريع: email
  3. number and rangenumber و range

    1. 8number and rangenumber و range
    2. 9سؤال سريع: range
  4. search, tel and urlsearch و tel و url

    1. 10search, tel and urlsearch و tel و url
    2. 11سؤال سريع: tel
  5. autocomplete and datalistالإكمال التلقائي و datalist

    1. 12autocomplete and datalistautocomplete و datalist
    2. 13سؤال سريع: datalist
  6. Page-structure elements: header, time, nav, figure, articleعناصر بنية الصفحة (1)

    1. 14Page-structure elements (1)عناصر البنية (1)
  7. Page-structure elements: summary/details, section, aside, meter, footer, mark, wbrعناصر بنية الصفحة (2)

    1. 15Page-structure elements (2)عناصر البنية (2)
    2. 16سؤال سريع: summary
    3. 17All page-structure elementsجدول عناصر البنية
  8. Page-structure elements: header, time, nav, figure, articleعناصر بنية الصفحة (1)

    1. 18سؤال سريع: article و aside
    1. 19الخلاصة