原型 - observe() 方法
此方法在元素上註冊事件處理程式並返回元素。
語法
element.observe(eventName, handler[, useCapture = false]);
返回值
一個 HTML 元素。
示例
<html>
<head>
<title>Prototype examples</title>
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
<script>
function RegisterFunction() {
$('test').observe('click', function(event) {
alert(Event.element(event).innerHTML);
});
}
</script>
</head>
<body onload = "RegisterFunction();">
<p id = "test">Click me to see the result.</p>
</body>
</html>
輸出
prototype_element_object.htm
廣告