Thẻ HTML <textareosystem
Thí dụ
Điều khiển nhập văn bản nhiều dòng (vùng văn bản):
<label for="w3review">Review of W3Schools:</label>
<textarea
id="w3review" name="w3review" rows="4" cols="50">
At w3schools.com you will learn how to make a website. They offer free tutorials in all web development technologies.
</textarea>
Thêm các ví dụ "Hãy tự mình thử" bên dưới.
Định nghĩa và Cách sử dụng
Thẻ <textarea>
xác định điều khiển nhập văn bản nhiều dòng.
Phần <textarea>
tử thường được sử dụng trong một biểu mẫu, để thu thập thông tin đầu vào của người dùng như nhận xét hoặc đánh giá.
Một vùng văn bản có thể chứa số lượng ký tự không giới hạn và văn bản hiển thị bằng phông chữ có chiều rộng cố định (thường là Courier).
Kích thước của một vùng văn bản được chỉ định bởi các thuộc tính <cols>
và <rows>
(hoặc bằng CSS).
Thuộc name
tính cần thiết để tham chiếu dữ liệu biểu mẫu sau khi biểu mẫu được gửi (nếu bạn bỏ qua
name
thuộc tính, sẽ không có dữ liệu nào từ vùng văn bản được gửi).
Thuộc id
tính này là cần thiết để liên kết vùng văn bản với một nhãn.
Mẹo: Luôn thêm thẻ <label> để có các phương pháp hỗ trợ tiếp cận tốt nhất!
Hỗ trợ trình duyệt
Element | |||||
---|---|---|---|---|---|
<textarea> | Yes | Yes | Yes | Yes | Yes |
Thuộc tính
Attribute | Value | Description |
---|---|---|
autofocus | autofocus | Specifies that a text area should automatically get focus when the page loads |
cols | number | Specifies the visible width of a text area |
dirname | textareaname.dir | Specifies that the text direction of the textarea will be submitted |
disabled | disabled | Specifies that a text area should be disabled |
form | form_id | Specifies which form the text area belongs to |
maxlength | number | Specifies the maximum number of characters allowed in the text area |
name | text | Specifies a name for a text area |
placeholder | text | Specifies a short hint that describes the expected value of a text area |
readonly | readonly | Specifies that a text area should be read-only |
required | required | Specifies that a text area is required/must be filled out |
rows | number | Specifies the visible number of lines in a text area |
wrap | hard soft |
Specifies how the text in a text area is to be wrapped when submitted in a form |
Thuộc tính toàn cầu
Thẻ <textarea>
cũng hỗ trợ Thuộc tính chung trong HTML .
Thuộc tính sự kiện
Thẻ <textarea>
cũng hỗ trợ Thuộc tính sự kiện trong HTML .
Các ví dụ khác
Thí dụ
Tắt tùy chọn thay đổi kích thước mặc định:
<html>
<head>
<style>
textarea {
resize: none;
}
</style>
</head>
<body>
<label for="w3review">Review of W3Schools:</label>
<textarea id="w3review" name="w3review" rows="4" cols="50">
At
w3schools.com you will learn how to make a website. They offer free tutorials
in all web development technologies.
</textarea>
</body>
</html>
Các trang liên quan
Tham chiếu DOM HTML: Đối tượng Textarea
Hướng dẫn CSS: Biểu mẫu tạo kiểu
Cài đặt CSS mặc định
Không có.