舉例如下
function run() {
var s = document.getElementById("show");
s.innerHTML = "Cutted!";
}
/* 《程式語言教學誌》的範例程式
http://pydoing.blogspot.com/
檔名:event016.js
功能:示範 JavaScript 程式
作者:張凱慶
時間:西元 2011 年 8 月 */如果使用者剪下文字,網頁會在 id 屬性為 show 的元素中印出提示訊息 Cutted
var s = document.getElementById("show");
s.innerHTML = "Cutted!";我們以下面的 HTML 文件載入
<!DOCTYPE html>
<html>
<head>
<title>HTML DOM DEMO</title>
<script src="event016.js" type="text/javascript"></script>
</head>
<body>
<textarea oncopy="run();">There is no spoon.</textarea>
<div id="show"></div>
</body>
</html>
<!-- 《程式語言教學誌》的範例程式
http://pydoing.blogspot.com/
檔名:event016.html
功能:示範 JavaScript 程式
作者:張凱慶
時間:西元 2011 年 8 月 -->其中的 <textarea> 元素設置 oncut 屬性,當使用者進行剪下之時,就會執行 run()
<textarea oncopy="run();">There is no spoon.</textarea>
瀏覽器 (broswer) 開啟網頁檔案,文字輸入區域有一句英文 There is no spoon.

反白剪下 poon ,就會印出 Cutted

| 中英文術語對照 | |
|---|---|
| 元素 | element |
| 屬性 | element |
| 瀏覽器 | broswer |
您可以繼續參考
HTML 元素的事件處理屬性
- 拷貝 oncopy
- 剪下 oncut
- 貼上 onpaste
- 離開焦點 onblur
- 更改 onchange
- 點擊 onclick
- 雙重點擊 ondbclick
- 進入焦點 onfocus
- 按住按鍵 onkeydown
- 按按鍵 onkeypress
- 釋放按鍵 onkeyup
- 按住滑鼠 onmousedown
- 滑鼠移動 onmousemove
- 離開目標元素 onmouseout
- 進入目標元素 onmouseover
- 釋放滑鼠 onmouseup
- 滾動滑鼠滾輪 onmousewheel
- 調整瀏覽器視窗大小 onresize
- 使用滑鼠滾輪 onscroll
- 滑鼠「拖」 ondrag
- 滑鼠「放」 ondrop
- 載入網頁 onload
相關目錄
HTML DOM 快速導覽
JavaScript 教材
首頁
參考資料
https://developer.mozilla.org/en/DOM/element.oncut
http://www.whatwg.org/specs/web-apps/current-work/multipage/elements.html#elements-in-the-dom
沒有留言:
張貼留言