【问题标题】:how to select event by class in prototype如何在原型中按类选择事件
【发布时间】:2009-12-07 16:28:14
【问题描述】:

在 jQuery 中。我正在按类调用一个事件。你如何在原型中做同样的事情。

$(".button").click(function() {
  var element = $(this);
  var Id = element.attr("id");
});

【问题讨论】:

    标签: jquery class events prototypejs


    【解决方案1】:
    $$('.button').observe('click', respondToClick);
    
    function respondToClick(event) {
       var element = event.element();
       var Id = element.id;
    }
    

    http://www.prototypejs.org/api/event

    【讨论】:

    • 你有一些乱七八糟的引号,我认为你的意思是 $$(),而不是 $()。
    【解决方案2】:
    Event.observe($$('.button'), 'click', function(e) {
        // ...
    });
    

    【讨论】:

      猜你喜欢
      • 2023-04-09
      • 1970-01-01
      • 2013-06-10
      • 2016-03-20
      • 2014-03-27
      • 1970-01-01
      • 2011-03-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多