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("您已選中部分文字!");
}
自己動手試一試 »