onselect 事件
更多“自己尝试”的例子见下文。
描述
onselect 事件在元素中的部分文本被选中后发生。
onselect 事件主要用于 <input type="text"> 或 <textarea> 元素。
浏览器支持
事件 | |||||
---|---|---|---|---|---|
onselect | 是 | 是 | 是 | 是 | 是 |
语法
技术详情
冒泡 | 否 |
---|---|
可取消 | 否 |
事件类型 | 如果从用户界面生成,则是 UiEvent;否则是 Event |
HTML 标签 | <input type="file">、<input type="password">、<input type="text"> 和 <textarea> |
DOM 版本 | 二级事件 |
更多示例
示例
使用 HTML DOM Input Text Object 的 select() 方法选择文本字段中的部分内容。当这种情况发生时,onselect 事件将触发,这将触发一个 alert 函数。
// 选择文本字段中的内容
function mySelectFunction() {
document.getElementById("myText").select();
}
// 在文本字段中的文本被选中时提示一段文字
function myAlertFunction() {
alert("您已选中部分文本!");
}
自己动手试一试 »