onselect event


onselect Event

Instance

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script>
function myFunction(){
	alert("你选中了一些文本");
}
</script>
</head>
<body>

一些文本: <input type="text" value="Hello world!" onselect="myFunction()">

</body>
</html>

Run Instance»

Click "Run instance" button to view the online instance


Definition and usage

onselect event occurs when the text in the text box is selected.

Syntax

HTML:

<elementonselect="SomeJavaScriptCode">

In JavaScript:

object.onselect=function(){SomeJavaScriptCode}

ParametersDescription
SomeJavaScriptCodeRequired. Specifies the JavaScript to be executed when this event occurs.


Browser Support

QQ截图20161108165429.png

##All major browsers support the onselect event


onselect In HTML the

onselect attribute can be used for: <input type="file">, <input type="password">, <input type="text ">, <keygen>, and <textarea>.