A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.cdn.mozilla.net/de/docs/Web/API/HTMLInputElement/selectionEnd below:

HTMLInputElement: selectionEnd Eigenschaft - Web-APIs

HTMLInputElement: selectionEnd Eigenschaft

Baseline Widely available

Die selectionEnd-Eigenschaft der HTMLInputElement-Schnittstelle ist eine Zahl, die den Endindex des ausgewählten Textes darstellt. Wenn keine Auswahl vorhanden ist, gibt diese den Versatz des Zeichens zurück, das unmittelbar nach der aktuellen Textcursorposition folgt.

Hinweis: Laut der WHATWG Forms Spezifikation gilt die selectionEnd-Eigenschaft nur für Eingabefelder der Typen text, search, URL, tel und password. In modernen Browsern tritt eine Ausnahme auf, wenn die selectionEnd-Eigenschaft auf den restlichen Eingabetypen gesetzt wird. Außerdem gibt diese Eigenschaft null zurück, wenn auf die selectionEnd-Eigenschaft bei Nicht-Text-Eingabeelementen zugegriffen wird.

Wenn selectionEnd kleiner als selectionStart ist, werden beide als der Wert von selectionEnd behandelt.

Wert

Eine nicht-negative Zahl.

Beispiele HTML
<!-- using selectionEnd on non text input element -->
<label for="color">selectionStart property on type=color</label>
<input id="color" type="color" />

<!-- using selectionEnd on text input element -->
<fieldset>
  <legend>selectionEnd property on type=text</legend>
  <label for="pin">Input PIN</label>
  <input type="text" id="pin" value="impossible PIN: 102-12-145" />
  <button id="pin-btn" type="button">PIN correction</button>
</fieldset>
JavaScript
const colorEnd = document.getElementById("color");
const text = document.querySelector("#pin");
const pinBtn = document.querySelector("#pin-btn");
const validPinChecker = /^\d{3}-\d{2}-\d{3}/g;
const selectionEnd = text.value.length;
const selectedText = text.value.substring(text.selectionStart, selectionEnd);

pinBtn.addEventListener("click", () => {
  const correctedText = selectedText.replace(validPinChecker, "");
  text.value = correctedText;
});

// open browser console to verify output
console.log(colorEnd.selectionEnd); // Output : null
Ergebnis Spezifikationen Browser-Kompatibilität Siehe auch MDN-Feedback-Box War diese Übersetzung hilfreich?

Diese Seite wurde automatisch aus dem Englischen übersetzt.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4