onselect Event
Příklad
Spusťte JavaScript, když byl vybrán nějaký text:
<input type="text" onselect="myFunction()">
Další příklady „Vyzkoušejte si to sami“ níže.
Definice a použití
K události onselect dojde poté, co byl v prvku vybrán nějaký text.
Událost onselect se většinou používá u prvků <input type="text"> nebo <textarea>.
Podpora prohlížeče
Event | |||||
---|---|---|---|---|---|
onselect | Yes | Yes | Yes | Yes | Yes |
Syntax
V HTML:
<element onselect="myScript">
V JavaScriptu:
object.onselect = function(){myScript};
V JavaScriptu pomocí metody addEventListener():
object.addEventListener("select", myScript);
Poznámka: Metoda addEventListener() není podporována v aplikaci Internet Explorer 8 a starších verzích.
Technické údaje
bubliny: | Ne |
---|---|
Zrušitelné: | Ne |
Typ události: | UiEvent , pokud je generován z uživatelského rozhraní, Event jinak |
Podporované HTML tagy: | <input type="file">, <input type="password">, <input type="text"> a <textarea> |
Verze DOM: | Události úrovně 2 |
Další příklady
Příklad
Použití metody select() vstupního textového objektu HTML DOM k výběru určitého obsahu textového pole. Když k tomu dojde, spustí se událost onselect, která spustí funkci výstrahy.
// Select the contents of a text field
function mySelectFunction() {
document.getElementById("myText").select();
}
// Alert some text when the text in the text field has been selected
function myAlertFunction() {
alert("You selected some text!");
}