我正在尝试获取点击的元素,以便我可以添加类。 Meteor是否提供了获取当前元素的任何方法,如jQuery $(this)
Template.retraining.events({
'click .myclass': function (event) {
//Get the clicked element like $(this) in jQuery
$().addClass('existing-col');
}
});
答案 0 :(得分:5)
要获取发生事件的元素,请使用event
object。
event.target
正如您所包含的jQuery,您可以将元素包装在jQuery中以使用jQuery方法。
$(event.target)
您可以在Meteor Tutorial
中看到这一点答案 1 :(得分:1)
通过这一点,您可以通过一键点击事件获得文本框值。
试试这个:
Template.retraining.events({
'click .myclass':function(e,t){
var val = t.find(".classname").value;
}