- 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
广告