Ein Eingabefeld, in dem der Benutzer einen Text eingeben kann. Die textbox
ist ähnlich wie das HTML input
Element. Nur eine Textzeile wird im Standardverhalten angezeigt. Das multiline
Attribut kann das Feld auch mit mehreren Zeilen ausstatten.
Weitere Informationen sind im XUL Tutorial verfügbar.
- Attribute
- cols, decimalplaces, disabled, emptytext, hidespinbuttons, increment, label, max, maxlength, min, multiline, newlines, onchange, oninput, placeholder, preference, readonly, rows, searchbutton, size, spellcheck, tabindex, timeout, type, value, wrap, wraparound
- Eigenschaften
- accessibleType, clickSelectsAll, decimalPlaces, decimalSymbol, defaultValue, disabled, editor, emptyText, increment, inputField, label, max, maxLength, min, placeholder, readOnly, searchButton, selectionEnd, selectionStart, size, spinButtons, tabIndex, textLength, timeout, type, value, valueNumber, wrapAround
- Methoden
- decrease, increase, reset, select, setSelectionRange
- Styleklassen
- plain
Besipiele
<vbox> <label control="your-name" value="Enter your name:"/> <textbox id="your-name" value="John"/> </vbox>
Attribute
cols
- Typ: integer
- Stellt die Anzahl an Spalten für mehrzeilige Textboxen dar.
decimalplaces
- Typ: integer
- Die Anzahl an Dezimalstellen, die angezeigt werden sollen. Der Standardwert ist 0, was bedeutet, dass keine Dezimalstellen angezeigt werden. Der Wert
infinity
kann dazu verwendet werden, keine Begrenzung der Dezimalstellen bei Zahlen anzuzeigen. Hinweis: Dezimalzahlen werden als Floats gespeichert.
disabled
- Typ: boolean
- Kennzeichnet, ob ein Element deaktiviert ist oder nicht. Wenn das Element auf
true
gesetzt ist, ist das Element deaktiviert. Deaktivierte Elemente sind gewöhnlich mit einem grauen Text dargestellt. Wenn ein Element deaktiviert ist, wird es auf Anwenderaktionen nicht reagieren, es kann den Fokus nicht erlangen und dascommand
Ereignis wird nicht ausgelöst. Das Element wird allerdings noch auf Mausereignisse antworten. Um das Element zu aktivieren, ist es besser das Attribut zu entfernen als es auf den Wertfalse
zu setzen. Um den Wert dieses Attributs mittels JavaScript zu setzen oder abzurufen, sollte besser diedisabled
Eigenschaft verwendet werden.
emptytext
Unerwünscht Gecko 2- Typ: string
- Ein String, der in der Textbox angezeigt wird, falls diese keinen Wert besitzt. Dieses Attribut wurde vom
placeholder
Attribut in Gecko 2 ersetzt. Der alte Name bleibt zur Kompatibilität bestehen, aber Sie sollten Ihren Code aktualisieren.
- Type: integer
- The maximum value that the scale or number box may be set to. The default value is 100 for scales and Infinity for number boxes.
-
maxlength
- Type: integer
- The maximum number of characters that the textbox allows to be entered.
-
min
- Type: integer
- The minimum value the control's value may take. The default value is 0.
-
multiline
- Type: boolean
- If
true
, the textbox displays multiple lines. If the user presses Enter, a new line is started. Iffalse
, the textbox only allows entry of one line.
newlines
- Type: one of the values below
- How the text box handles pastes with newlines in them.
- Possible values:
pasteintact
- Paste newlines unchanged
pastetofirst
- Paste text up to the first newline, dropping the rest of the text
replacewithcommas
- Pastes the text with the newlines replaced with commas
replacewithspaces
- Pastes the text with newlines replaced with spaces
strip
- Pastes the text with the newlines removed
stripsurroundingwhitespace
- Pastes the text with newlines and adjacent whitespace removed
-
onchange
- Type: script code
- This event is sent when the value of the textbox is changed. The event is not sent until the focus is moved to another element.
preference
- Type: id
- Connects the element to a corresponding
preference
. This attribute only has any effect when used inside aprefwindow
. More information is available in the Preferences System article.
readonly
- Type: boolean
- If set to
true
, then the user cannot change the value of the element. However, the value may still be modified by a script.
-
rows
- Type: integer
-
The number of rows to display in the element. If the element contains more than this number of rows, a scrollbar will appear which the user can use to scroll to the other rows. To get the actual number of rows in the element, use the
getRowCount
method.
-
size
- Type: integer
- The number of characters that can be displayed in the textbox.
-
spellcheck
- Type: boolean
-
If
true
, spell checking is enabled by default for the text box; iffalse
, spell checking is disabled by default. -
If not specified, this defaults to
false
The HTML
The spellcheck
attribute uses values of true or false (you cannot simply add the spellcheck attribute to a given element):
<!-- spellcheck everything! -->
<input type="text" spellcheck="true" /><br />
<textarea spellcheck="true"></textarea>
<div contenteditable="true" spellcheck="true">I am some content</div>
<!-- spellcheck nothing! -->
<input type="text" spellcheck="false" /><br />
<textarea spellcheck="false"></textarea>
<div contenteditable="true" spellcheck="false">I am some content</div>
You can use spellcheck on INPUT
, TEXTAREA
, and contenteditable
elements. Thespellcheck
attribute works well paired with the autocomplete, autocapitalize, and autocorrect attributes too!
Added from David Walsh's article on Spell Check.
-
tabindex
- Type: integer
- The tab order of the element. The tab order is the order in which the focus is moved when the user presses the "
tab
" key. Elements with a highertabindex
are later in the tab sequence.
timeout
- Type: integer
- For autocomplete textboxes, the number of milliseconds before the textbox starts searching for completions. The default is 50 milliseconds. For search textboxes, the number of milliseconds before the timer fires a command event. The default is 500 milliseconds. For timed textboxes, the number of milliseconds before the timer fires a command event. There is no default. The timer starts after the user types a character. If the user types another character, the timer resets.
type
- Type: one of the values below
- You can set the type attribute to one of the values below for a more specialized type of textbox. Don't set the type if you wish to use a regular textbox.
-
autocomplete
- A textbox that supports autocomplete. For more information about autocomplete textboxes, see the autocomplete documentation (XPFE [Thunderbird/SeaMonkey]) (Firefox)
number
- A textbox that only allows the user to enter numbers. In addition, arrow buttons appear next to the textbox to let the user step through values. There are several attributes that allow the number textbox to be configured, including
decimalplaces
,min
,max
,increment
,wraparound
,hidespinbuttons
, andtextbox.value
. password
- A textbox that hides what is typed, used for entering passwords.
search
- A textbox intended for searching. The command event will fire as the user modifies the value. A listener for the command event should update search results. If the
searchbutton
attribute is set totrue
, the command event is only fired if the user presses the search button or presses theEnter
key. You may specify grey text to appear when the search box is empty using theemptytext
attribute, and a timeout may be set for the command event using thetimeout
attribute (defaults to 500). timed
- This textbox will fire a command event after the user types characters and a certain time has passed. The delay is set with the
timeout
attribute. The command event will fire if the user presses theEnter
key. Thetimed
type is deprecated in Gecko 1.9.1 and thesearch
textbox may be used instead.
-
value
- Type: string
- The default value entered in a textbox. The attribute only holds the default value and is never modified when the user enters text. To get the updated value, use the
value
property. For number boxes, the default is 0 or the minimum value returned by themin
property, whichever is higher.
-
wrap
- Type: string
- Set this attribute to the value
off
to disable word wrapping in the textbox. If this attribute is not specified, word wrapping is enabled.
-
wraparound
- Type: boolean
- If
true
, the value of the number box will wrap around when the maximum or minimum value is exceeded. The minimum and maximum values must both not be infinity.
Eigenschaften
placeholder
- Type: string
- A string that appears in the textbox when it has no value.
Methoden
Styleklassen
Folgende Klassen können benutzt werden, um den Stil des Elements zu bestimmen. Statt den Stil des Elements direkt zu ändern, sollten diese Klassen zu Hilfe genommen werden, da sie sich natürlicher in das vom Benutzer gewählte Theme der Benutzeroberfläche einfügen.
-
plain
- This class causes the element to be displayed with no border or margin.
Hinweise
Das maxlength
Attribut funktioniert nicht, wenn man im Mehrzeilenmodus ist. Ein Workaround mittels JavaScript und dem onkeypress
Eventhandler stellt eine Lösung dar.
Das XUL script:
<textbox id="pnNote" multiline="true" rows="2" cols="70" onkeypress="return pnCountNoteChars(event);"/>
Das Javascript:
function pnCountNoteChars(evt) { //Erlaube Tasten, die keine Zeichen sind (Entfernen, Backspace etc.) if ((evt.charCode == 0) && (evt.keyCode != 13)) return true; if(evt.target.value.length < 10) { return true; } else { return false; } }
Verwandte Themen
- Schnittstellen
- nsIAccessibleProvider, nsIDOMXULTextboxElement