Javascript 如何在meteor中单击更改图标
在meteor中,我尝试在单击时更改图标更改(我使用了图标图标图标),以将收藏夹添加到列表中。我使用了toggleClass()。但它不起作用,。这里我附上我的代码。当我刷新页面时,图标没有改变。有人能帮我解决这个问题吗。 HTML代码:Javascript 如何在meteor中单击更改图标,javascript,jquery,html,css,meteor,Javascript,Jquery,Html,Css,Meteor,在meteor中,我尝试在单击时更改图标更改(我使用了图标图标图标),以将收藏夹添加到列表中。我使用了toggleClass()。但它不起作用,。这里我附上我的代码。当我刷新页面时,图标没有改变。有人能帮我解决这个问题吗。 HTML代码: <span class="glyphicon glyphicon-star-empty" style="color:green"></span> 您必须定义一个事件: Template.YourTemplateName.events(
<span class="glyphicon glyphicon-star-empty" style="color:green"></span>
您必须定义一个事件:
Template.YourTemplateName.events({
"click .glyphicon": function(){
$(event.target).toggleClass('glyphicon-star-empty glyphicon-star');
}
});
您必须定义一个事件:
Template.YourTemplateName.events({
"click .glyphicon": function(){
$(event.target).toggleClass('glyphicon-star-empty glyphicon-star');
}
});
这应该有效:Template.TemplateName.events({
$('.glyphicon')。单击(函数(){
$(event.currentTarget).toggleClass('glyphicon-star-empty glyphicon-star');
})
这应该有效:Template.TemplateName.events({
$('.glyphicon')。单击(函数(){
$(event.currentTarget).toggleClass('glyphicon-star-empty glyphicon-star');
})
这是您如何做到的:
Template.TemplateName.events({
"click .glyphicon": function(event){
$(event.currentTarget).toggleClass('glyphicon-star-empty glyphicon-star');
});
这就是你如何做到这一点:
Template.TemplateName.events({
"click .glyphicon": function(event){
$(event.currentTarget).toggleClass('glyphicon-star-empty glyphicon-star');
});
它工作正常..是否添加jquery.js?检查此链接:1)检查min.js文件。包括与否。它工作正常..是否添加jquery.js?检查此链接:1)检查min.js文件。包括与否。
此
将是模板的数据上下文,而不是DOM元素。您需要$(event.target).toggleClass()
Right@MichelFloyd这将是模板的数据上下文,而不是DOM元素。您需要$(event.target).toggleClass()
Right@MichelFloyd