问题
I'm trying to get the clicked element so that I can add class. Does Meteor provides any way to get the current element like jQuery $ (this)
Template.retraining.events({
'click .myclass': function (event) {
//Get the clicked element like $(this) in jQuery
$().addClass('existing-col');
}
});
回答1:
To get the element on which the event occurred, use event
object.
event.target
As you've jQuery included, you can wrap the element in jQuery to use jQuery methods on it.
$(event.target)
You can see this in Meteor Tutorial
回答2:
From this you can get textbox value with one button click event.
Try this:
Template.retraining.events({
'click .myclass':function(e,t){
var val = t.find(".classname").value;
}
来源:https://stackoverflow.com/questions/35194509/meteorjs-how-to-get-clicked-element