【问题标题】:How to get current element attributes from click event in Meteor?如何从 Meteor 中的点击事件中获取当前元素属性?
【发布时间】:2014-10-11 02:58:17
【问题描述】:

假设我有这样的事情:

'click #url_image': function(e) { 
  var className = $(this).attr("class");
  console.log(className);
}

meteor 中的“this”是当前模板的上下文,而不是被点击的实际项目。如何从实际的点击事件中获取类或其他属性,在这种情况下是#url_image 的类?

谢谢

【问题讨论】:

    标签: meteor


    【解决方案1】:

    试试

    $(e.currentTarget).attr("class");
    

    【讨论】:

      【解决方案2】:

      或者如果你想要一个非 jQuery 解决方案:

      e.currentTarget.getAttribute('class');
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-11-18
        • 1970-01-01
        • 2020-01-06
        • 2015-09-14
        • 1970-01-01
        • 1970-01-01
        • 2015-01-18
        • 2021-02-24
        相关资源
        最近更新 更多