onselect 事件
当文本被选中时,执行一段 JavaScript代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>蜜蜂教程(mifengjc.com)</title>
<script>
function myFunction() {
alert("你选中了一些文本");
}
</script>
</head>
<body>
一些文本: <input type="text" value="Hello world!" onselect="myFunction()">
</body>
</html>
定义和用法
onselect 事件会在文本框中的文本被选中时发生。
语法
HTML 中:
<element onselect="SomeJavaScriptCode">
JavaScript 中:
object.onselect = function() {
SomeJavaScriptCode
}
参数 | 描述 |
---|---|
SomeJavaScriptCode | 必需。规定该事件发生时执行的 JavaScript。 |
浏览器支持
所有主要浏览器都支持 onselect 事件
onselect 在 HTML 中
onselect 属性可用于: <input type="file">, <input type="password">, <input type="text">, <keygen>, 和 <textarea>.
