【发布时间】:2017-09-29 12:40:12
【问题描述】:
这个 Meteor 模板代码尝试在没有不必要的调用的情况下向元素添加类。 event.currentTarget.addClass('active'); 加课失败?我做错了什么?
// inside the template events
'click #login-form-link': function (event) {
$('#login-form-link').addClass('active'); // extra call
event.currentTarget.addClass('active'); // cheap but did not work
},
【问题讨论】:
-
你有什么问题?
-
event.currentTarget.addClass is not a function 是浏览器控制台上的错误。
-
这是一个jQuery方法,所以是
$(event.currentTarget).addClass('active');或event.currentTarget.classList.add('active'); -
那是因为 event.currentTarget 对象不是 jquery 对象,所以你不能在它上面调用
addClass()。您需要先使用选择器找到它 -
$(this).addClass('active')也失败了,
标签: javascript jquery meteor