Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

textbox

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

Image:XUL_ref_textbox.png
<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 das command 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 Wert false zu setzen. Um den Wert dieses Attributs mittels JavaScript zu setzen oder abzurufen, sollte besser die disabled 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.
hidespinbuttons
Typ: boolean
Falls der Wert auf true gesetzt wird, werden keine Buttons mit Pfeilen angezeigt, um den Wert des Feldes anzupassen. Der Wert kann dann ausschließlich per Tastatur eingegeben werden. Standardmäßig ist der Wert false.
increment
Type: integer
The amount by which the curpos (for scroll bars) or value (for number boxes and scale) attribute changes when the arrows are clicked(or scales are dragged). The default value is 1.
label
Type: string
If present and not empty, this will be exposed to screen readers through the label property.
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. If false, 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.
oninput
Type: script code
This event is sent when a user enters text in a textbox. This event is only called when the text displayed would change, thus it is not called when the user presses non-displayable keys.
preference
Type: id
Connects the element to a corresponding preference. This attribute only has any effect when used inside a prefwindow. 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.
searchbutton
Type: boolean
If true, the search field will only fire a command event when the user presses the search button or presses the Enter key. Otherwise, the command event is fired whenever the user modifies the value. This attribute only applies to textboxes with the type search.
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; if false, 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 INPUTTEXTAREA, 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 higher tabindex 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, and textbox.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 to true, the command event is only fired if the user presses the search button or presses the Enter key. You may specify grey text to appear when the search box is empty using the emptytext attribute, and a timeout may be set for the command event using the timeout 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 the Enter key. The timed type is deprecated in Gecko 1.9.1 and the search 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 the min 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

Geerbte Methoden
element.addEventListener(), node.appendChild(), blur, click, node.cloneNode(), node.compareDocumentPosition(), element.dispatchEvent(), doCommand, focus, element.getAttribute(), element.getAttributeNode(), element.getAttributeNodeNS(), element.getAttributeNS(), element.getBoundingClientRect(), element.getClientRects(), getElementsByAttribute, getElementsByAttributeNS, element.getElementsByClassName(), element.getElementsByTagName(), element.getElementsByTagNameNS(), node.getFeature(), node.getUserData(), element.hasAttribute(), element.hasAttributeNS(), nodes.hasAttributes(), nodes.hasChildNodes(), node.insertBefore(), node.isDefaultNamespace(), node.isEqualNode(), node.isSameNode(), node.isSupported(), node.lookupNamespaceURI(), node.lookupPrefix(), node.normalize(), element.querySelector(), element.querySelectorAll(), element.removeAttribute(), element.removeAttributeNode(), element.removeAttributeNS(), node.removeChild(), element.removeEventListener(), node.replaceChild(), element.setAttribute(), element.setAttributeNode(), element.setAttributeNodeNS(), element.setAttributeNS(), node.setUserData()

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

Schlagwörter des Dokuments und Mitwirkende

Schlagwörter: 
 Mitwirkende an dieser Seite: fscholz, [email protected]
 Zuletzt aktualisiert von: fscholz,