onselect
定义和用法
onselect属性在选取元素文本后触发。
onselect属性可使用于以下元素:<input type="file">、<input type="password">、<input type="text">、<keygen>、<textarea>。
语法
<element onselect="script">
浏览器支持
![]() | ![]() | ![]() | ![]() | ![]() |
所有主流浏览器都支持onselect事件属性 | ||||
示例
<script>
function myFunction(){
alert("你选中了一些文本");
}
</script>
一些文本: <input type="text" value="Hello world!" onselect="myFunction()">
<p>请选中上面的Hello world触发代码</p>
HTML 4.01 与 HTML5之间的差异
无。
属性值
| 值 | 描述 |
|---|---|
| script | 规定该onselect事件触发时执行的脚本。 |
实例
当选取<input>元素中的文本后执行javascript:<input type="text" onselect="showmsg() value="hello world!">





