Znacznik HTML <textarea>
Przykład
Wielowierszowa kontrolka wprowadzania tekstu (obszar tekstowy):
<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>
Więcej przykładów „Wypróbuj sam” poniżej.
Definicja i użycie
Znacznik <textarea>
definiuje wielowierszową kontrolkę wprowadzania tekstu.
Element <textarea>
jest często używany w formularzu do zbierania danych wejściowych użytkownika, takich jak komentarze lub recenzje.
Obszar tekstowy może zawierać nieograniczoną liczbę znaków, a tekst jest renderowany czcionką o stałej szerokości (zwykle Courier).
Rozmiar obszaru tekstowego jest określony przez atrybuty <cols>
i <rows>
(lub za pomocą CSS).
Atrybut jest name
potrzebny do odniesienia się do danych formularza po przesłaniu formularza (jeśli pominiesz
name
atrybut, żadne dane z obszaru tekstowego nie zostaną przesłane).
Atrybut jest id
potrzebny do skojarzenia obszaru tekstowego z etykietą.
Wskazówka: zawsze dodawaj tag <label> , aby uzyskać najlepsze praktyki ułatwień dostępu!
Obsługa przeglądarki
Element | |||||
---|---|---|---|---|---|
<textarea> | Yes | Yes | Yes | Yes | Yes |
Atrybuty
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 |
Atrybuty globalne
Znacznik <textarea>
obsługuje również atrybuty globalne w HTML .
Atrybuty wydarzenia
Tag <textarea>
obsługuje również Atrybuty Zdarzeń w HTML .
Więcej przykładów
Przykład
Wyłącz domyślną opcję zmiany rozmiaru:
<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>
Powiązane strony
Odniesienie HTML DOM: Obiekt Textarea
Samouczek CSS: stylizowanie formularzy
Domyślne ustawienia CSS
Nic.