observe(element, name, observer, useCapture) static element: object or id, name: event name (like 'click', 'load', etc), observer: function to handle the event, useCapture: if true, handles the event in the capture phase and if false in the bubbling phase. 为对象的某个事件增加一个处理函数。
<script>
Event.observe(window, 'load', showMessage, false);
function showMessage() {
alert('Page loaded.');
}
</script><script>
Event.observe($(inc_SchoolName[mark]), 'focus', function() {shows(mark)});
</script>
本文介绍了如何使用observe方法为DOM元素添加事件监听器。通过两个示例展示了如何为窗口加载事件和输入框聚焦事件添加处理函数。这有助于理解事件监听器的工作原理及其在不同阶段的应用。

被折叠的 条评论
为什么被折叠?



