定义和用法
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>。
实例
当文本被选中时,执行一段 Javascript代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Web176教程(web176.com)</title>
<script>
function myFunction(){
alert("你选中了一些文本");
}
</script>
</head>
<body>
一些文本: <input type="text" value="Hello world!" onselect="myFunction()">
</body>
</html>作者:terry,如若转载,请注明出处:https://www.web176.com/javascriptbook/domtips/3961.html
支付宝
微信