
- Prototype 教程
- Prototype - 主頁
- Prototype - 簡要概覽
- Prototype - 有用功能
- Prototype - 工具方法
- Prototype - Element 物件
- Prototype - 數字處理
- Prototype - 字串處理
- Prototype - 陣列處理
- Prototype - 雜湊處理
- Prototype - 基本物件
- Prototype - 模板化
- Prototype - 列舉
- Prototype - 事件處理
- Prototype - 表單管理
- Prototype - JSON 支援
- Prototype - AJAX 支援
- Prototype - 表達範圍
- Prototype - 定期間隔執行
- Prototype 有用資源
- Prototype - 快速指南
- Prototype - 有用資源
- Prototype - 討論
Prototype - Event element() 方法
此方法返回事件發生的 DOM 元素。
語法
Event.element();
返回值
返回事件發生的 DOM 元素。
示例
以下是一個簡單的程式碼,它允許你在頁面上的任意位置單擊,如果你直接單擊段落,則會隱藏它們。
<html> <head> <title>Prototype examples</title> <script type = "text/javascript" src = "/javascript/prototype.js"></script> <script> // Register event 'click' and associated call back. Event.observe(document, 'click', respondToClick); // Callback function to handle the event. function respondToClick(event) { var element = event.element(); alert("Tag Name : " + element.tagName ); if ('P' == element.tagName) { element.hide(); } } </script> </head> <body> <p id = "note"> Click on any part to see the result.</p> <p id = "para">This is paragraph</p> <div id = "division">This is divsion.</div> </body> </html>
輸出
prototype_event_handling.htm
廣告