原型 - 按元素类名称单击事件 [英] Prototype - click event by element class name
本文介绍了原型 - 按元素类名称单击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是原型框架的新手,我正在尝试一些非常简单且失败的东西。我试图回复按钮上的点击事件,如下所示:
I am new to the prototype framework and am trying something really simple and failing. I am trying to respond to a click event on a button like so:
$$('.btn').observe('click', respond);
function respond(event) {
alert("hello");
}
为什么这不起作用?请帮助!
Why isnt this working?? Please help!
推荐答案
与jQuery不同,在Prototype中处理具有多个结果的选择器的工作方式略有不同。您需要使用 .each()
分别处理每个选定的结果。
Unlike jQuery, handing selectors with multiple results in Prototype works a little differently. You need to handle each selected result separately using .each()
.
$$('.btn').each(function(element) {
element.observe('click', respond);
})
这是我转移到jQuery的原因之一。另一个原因是:知道jQuery是可销售的并且知道Prototype不是。
This is one of the reasons I moved over to jQuery. The other reason: knowing jQuery is marketable and knowing Prototype is not.
这篇关于原型 - 按元素类名称单击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文