Call a function when some text has been selected:
<input type="text" onselect="myFunction()">
Try it Yourself »
More "Try it Yourself" examples below.
The onselect event occurs after some text has been selected in an element.
The onselect event is mostly used on <input type="text"> or <textarea> elements.
Event | |||||
---|---|---|---|---|---|
onselect | Yes | Yes | Yes | Yes | Yes |
In JavaScript, using the addEventListener() method:
object.addEventListener("select",
myScript);
Try it Yourself »
Bubbles: | No |
---|---|
Cancelable: | No |
Event type: | UiEvent if generated from a user interface, Event otherwise |
HTML tags: | <input type="file">, <input type="password">, <input type="text">, and <textarea> |
DOM Version: | Level 2 Events |
Using the select() method of the HTML DOM Input Text Object to select some content of a text field. When this happens, the onselect event fires, which will trigger an alert function.
// 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!");
}
Try it Yourself »
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!