XHTML cú pháp
There are certain syntax rules in XHTML that must be followed. Có những quy tắc cú pháp nhất định trong XHTML phải được theo sau.
This lesson focuses on: Bài học này tập trung vào:
XHTML syntax rules XHTML cú pháp quy
XHTML syntax rules XHTML cú pháp quy
These syntax rules are not the same as the tag rules discussed in the differences between HTML and XHTML lesson, though some of the information from that lesson is repeated here. Những quy tắc cú pháp là không giống như các quy tắc thẻ thảo luận trong sự khác biệt giữa HTML và bài học XHTML, mặc dù một số thông tin từ bài học đó là lặp đi lặp lại ở đây.
The syntax rules presented in this lesson mostly revolve around tag attributes. Cú pháp luật được trình bày trong bài học này chủ yếu xoay quanh các thuộc tính khóa.
Quick list of syntax rules Nhanh danh sách các quy tắc cú pháp
Attribute names must be in lower-case Tên các thuộc tính phải được trong trường hợp thấp hơn
Attribute values must be quoted Các giá trị thuộc tính phải được trích dẫn
Attributes cannot be minimized Thuộc tính không thể được giảm thiểu tối đa
The name attribute is replaced by the id attribute Thuộc tính tên được thay thế bởi các thuộc tính id
Some elements are mandatory Một số yếu tố bắt buộc
Attribute names must be in lower-case Tên các thuộc tính phải được trong trường hợp thấp hơn
Not just attributes, but tags as well must all be in lowercase in XHTML. Không chỉ là các thuộc tính, nhưng thẻ cũng như tất cả phải ở trong chữ thường trong XHTML.
Example with uppercase attributes and tags: Ví dụ với thuộc tính chữ hoa và các thẻ:
<html> <head> <TITLE>Tags properly closed</TITLE> </head> <body> <TABLE> <TR> <TD ALIGN="CENTER">Cell 1</TD> <TD ALIGN="CENTER">Cell 2</TD> </TR> </body> </html> <html> <head> Tags <TITLE> đúng đóng </ TITLE> </ head> <body> <table> <TR> <TD ALIGN="LEFT"> Cell 1 </ TD> <TD align = "center" > Cell 2 </ TD> </ TR> </ body> </ html>
The above example fixed to conform to proper XHTML syntax: Ví dụ trên cố định để phù hợp với cú pháp XHTML thích hợp:
<html> <head> <title>Tags properly closed</title> </head> <body> <table> <tr> <td align="center">Cell 1</td> <td align="center">Cell 2</td> </tr> </body> </html> <html> <head> <title> Tags đúng đóng </ title> </ head> <body> <table> <div align="center"> Cell 1 </ td> <td align = "trung tâm" > Cell 2 </ td> </ tr> </ body> </ html>
Attribute values must be quoted Các giá trị thuộc tính phải được trích dẫn
Attributes should always be quoted. Thuộc tính luôn cần được trích dẫn. Even though a page may appear as you intend it to even if you don't quote attributes, the page will not validate with an HTML validator. Mặc dù một trang có thể xuất hiện khi bạn có ý định để ngay cả khi bạn không báo thuộc tính, trang web sẽ không xác nhận với một validator HTML. Also, if the value given to the attribute that is not quoted has at least one space, the page may actually not appear as you intend it to. Ngoài ra, nếu giá trị cho các thuộc tính đó không phải là trích dẫn có ít nhất một không gian, trang web có thể thực sự không xuất hiện như bạn có ý định nó.
Example of not quoting attributes: Ví dụ về trích dẫn không thuộc tính:
<input type="button" value=I am a button /> <br /><br /> <a href=http://www.yahoo.com target="_blank"> Yahoo search engine </a> <input type="button" value=I sáng một nút /> <br /> <br /> <a href=http://www.yahoo.com target="_blank"> Yahoo công cụ tìm kiếm </ a>
Output: Ra:
Yahoo search engine Yahoo công cụ tìm kiếm
In the above example, we omitted quotes from the value attribute of the <input> tag which in this case displays a button. Trong ví dụ trên, chúng tôi bỏ qua báo giá từ các thuộc tính giá trị của thẻ <input> mà trong trường hợp này sẽ hiển thị một nút. The text that is supposed to be displayed on the button is "I am a button", but only "I" is displayed since it cuts off after the space. Các văn bản đó là nghĩa vụ phải được hiển thị trên nút là "Tôi là một nút", nhưng chỉ có "tôi" được hiển thị vì nó cắt sau khi không gian. For the href attribute in the <a> tag, we omitted quotes as well, but it still works as intended. Đối với thuộc tính href trong thẻ <a>, chúng tôi bỏ qua báo giá là tốt, nhưng nó vẫn hoạt động như dự định.
The above example fixed to conform to proper XHTML syntax: Ví dụ trên cố định để phù hợp với cú pháp XHTML thích hợp:
<input type="button" value="I am a button" /> <br /><br /> <a href="http://www.yahoo.com" target="_blank"> Yahoo search engine </a> <input type="button" value="I am a button" /> <br /> <br /> <a href="http://www.yahoo.com" target="_blank"> Yahoo công cụ tìm kiếm < / a>
Output: Ra:
Yahoo search engine Yahoo công cụ tìm kiếm
Attributes cannot be minimized Thuộc tính không thể được giảm thiểu tối đa
There are some attributes in HTML that in the past have been minimized. Có một số thuộc tính trong HTML mà trong quá khứ đã được giảm thiểu. With XHTML, this cannot be done. Với XHTML, điều này không thể được thực hiện.
A list of attributes that are minimized in HTML, and how they should be coded in XHTML: Một danh sách các thuộc tính được thu nhỏ trong HTML, và làm thế nào họ nên được mã hoá trong XHTML:
Minimized attributes correct format Giảm thiểu những thuộc tính định dạng đúng HTML HTML XHTML XHTML
compact nhỏ gọn compact="compact" nhỏ gọn = "nhỏ gọn"
checked kiểm tra checked="checked" checked = "checked"
declare tuyên bố declare="declare" kê khai = "tuyên bố"
readonly readonly readonly="readonly" readonly = "readonly"
disabled vô hiệu hoá disabled="disabled" tật = "tàn tật"
selected lựa chọn selected="selected" chọn = "chọn"
defer hoãn defer="defer" hoãn = "hoãn"
ismap ismap ismap="ismap" ismap = "ismap"
nohref nohref nohref="nohref" nohref = "nohref"
noshade noshade noshade="noshade" noshade = "noshade"
nowrap nowrap nowrap="nowrap" nowrap = "nowrap"
multiple nhiều multiple="multiple" nhiều = "nhiều"
noresize noresize noresize="noresize" noresize = "noresize"
Example with minimized attributes: Ví dụ với thuộc tính giảm thiểu tối đa:
<form> <select name="numbers" id="numbers"> <option value="8" selected >8</option> <option value="10">10</option> <option value="24">24</option> <option value="40">40</option> </select> <textarea readonly ></textarea> </form> <form> <select name="numbers" id="numbers"> <option value="8" chọn> 8 </ option> <option value="10"> 10 </ option> <option value = "24" > 24 </ option> <option value="40"> 40 </ option> </ select> <textarea readonly> </ textarea> </ form>
The above example fixed to conform to proper XHTML syntax: Ví dụ trên cố định để phù hợp với cú pháp XHTML thích hợp:
<form> <select name="numbers" id="numbers"> <option value="8" selected="selected" >8</option> <option value="10">10</option> <option value="24">24</option> <option value="40">40</option> </select> <textarea readonly="readonly" ></textarea> </form> <form> <select name="numbers" id="numbers"> <option value="8" selected="selected"> 8 </ option> <option value="10"> 10 </ option> <option value = "24"> 24 </ option> <option value="40"> 40 </ option> </ select> <textarea readonly="readonly"> </ textarea> </ form>
The name attribute is replaced by the id attribute Thuộc tính tên được thay thế bởi các thuộc tính id
In HTML 4.01, there are certain tags which contain a name attribute including <a> , <applet> , <frame> , <iframe> , <img> , and <map> . Trong HTML 4.01, có một số thẻ có chứa một tên thuộc tính bao gồm <a>, <applet>, <frame>, <iframe>, <img>, và <map>. The name attribute is deprecated in XHTML, and instead the id attribute should be used. Thuộc tính tên là lỗi thời vào XHTML, và thay vào đó thuộc tính id nên được sử dụng.
NOTE: Even though the name attribute is deprecated in favor of the id attribute, use both attributes for backwards compatibility -- for older browsers. Chú ý: Mặc dù thuộc tính tên là lỗi thời vào lợi ích của thuộc tính id, sử dụng cả thuộc tính tương thích ngược - cho các trình duyệt cũ.
Example using only the name attribute: Ví dụ chỉ sử dụng các thuộc tính và tên:
<frame name="frame1" src="frame1.html" /> <img src="/images/pic1.jpg name="pic1" /> <frame name="frame1" src="frame1.html" /> <img src="/images/pic1.jpg name="pic1" />
The above example fixed to conform to proper XHTML syntax: Ví dụ trên cố định để phù hợp với cú pháp XHTML thích hợp:
<frame name="frame1" id="frame1" src="frame1.html" /> <img src="/images/pic1.jpg name="pic1" id="pic1" /> <frame name="frame1" id="frame1" src="frame1.html" /> <img src="/images/pic1.jpg name="pic1" id="pic1" />
Some elements are mandatory Một số yếu tố bắt buộc
XHTML documents must contain a doctype declaration. XHTML tài liệu phải có một tuyên bố DOCTYPE. Mandatory XHTML elements include the html , head , body , and title elements. XHTML phải nhập đầy đủ các yếu tố bao gồm html, đầu, cơ thể, và các yếu tố tiêu đề. The title element must be located inside the head element. Các phần tử tiêu đề phải được đặt bên trong các yếu tố đầu.
A basic XHTML document with the mandatory elements (including the doctype declaration): Một XHTML cơ bản tài liệu với các yếu tố bắt buộc (bao gồm cả việc kê khai DOCTYPE):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>XHTML is cool</title> </head> <body> XHTML is used to display content on webpages </body> </html> <DOCTYPE html PUBLIC "! - / / W3C / / DTD XHTML 1.0 Transitional / / EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title> XHTML là mát </ title> </ head> <body> XHTML được sử dụng để hiển thị nội dung trên các trang web </ body> </ html> NOTE: The doctype declaration is NOT an XHTML element, and not part of the XHTML document. Chú ý: Tờ khai DOCTYPE là không một phần tử XHTML, và không phải là một phần của tài liệu XHTML. The doctype declaration is used to declare which document type the XHTML document is. Tờ khai DOCTYPE được sử dụng để khai báo loại tài liệu đó là tài liệu XHTML.
The doctype declaration as well as the different document types you can have in XHTML are covered in the XHTML document types lesson. Tờ khai DOCTYPE cũng như các loại tài liệu khác nhau, bạn có thể có trong XHTML được bao gồm trong bài học XHTML loại tài liệu.
Practice Thực hành
Online code editor Online mã biên tập
Practical examples Ví dụ thực tế
Practical exercises Thực hiện các bài tập
Step-by-step tutorials Từng bước hướng dẫn
Reference Tham khảo
Terms glossary Thuật ngữ
Reference material Tài liệu tham khảo
Rate this site Tỷ lệ trang web này
Rate this site Tỷ lệ trang web này
Visitor comments Số người truy cập ý kiến