[英]Prototype - click event on an image
I am trying to respond to a click event on a image like so. 我正在尝试响应像这样的图像上的点击事件。 Why isn't this working?
为什么这不起作用?
$$('refresh').each(function(element) {
element.observe('click', respond);
})
function respond(event) {
alert("hello");
}
<img src="images/refresh.jpg" id="refresh" />
Updated 更新
Use $('refresh')
instead of $$('refresh')
, or $$('#refresh')
. 使用
$('refresh')
代替$$('refresh')
或$$('#refresh')
。 But second variant returns array anyway. 但是第二个变体仍然返回数组。 See links: $ and $$ .
查看链接: $和$$ 。 And I don't understand how do you bind event handler.
而且我不明白如何绑定事件处理程序。
All code: 所有代码:
<img id="refresh" src="images/refresh.jpg" />
<script>
$$('#refresh').each(function (element) {
Event.observe(element, 'click', respond);
});
function respond (event) {
alert("hello");
}
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.