简体   繁体   English

如何在流星点击中更改图标

[英]how to change an icon on click in meteor

In meteor, I am trying to change icon change on click (I used glyphicon Icons) to add favourites to list. 在流星中,我试图更改单击时的图标更改(我使用了glyphicon图标)以将收藏夹添加到列表中。 I used toggleClass(). 我使用过toggleClass()。 But it is not working,. 但这是行不通的。 Here I am attaching my code. 我在这里附上我的代码。 When I refresh the page the icon is not changing. 当我刷新页面时,图标没有改变。 Can anyone help me with solution. 谁能帮我解决方案。 HTML Code: HTML代码:

<span class="glyphicon glyphicon-star-empty" style="color:green"></span>

And JS Code: 和JS代码:

$(document).ready(function(){

    $('.glyphicon').click(function(){
    $(this).toggleClass('glyphicon-star-empty glyphicon-star');
    });
});

This is how you do this: 这是您的操作方式:

Template.TemplateName.events({
    "click .glyphicon": function(event){
         $(event.currentTarget).toggleClass('glyphicon-star-empty glyphicon-star');
});

You have to define an event: 您必须定义一个事件:

Template.YourTemplateName.events({
  "click .glyphicon": function(){
    $(event.target).toggleClass('glyphicon-star-empty glyphicon-star');
  }
});

这应该工作:
Template.TemplateName.events({ $('.glyphicon').click(function(){ $(event.currentTarget).toggleClass('glyphicon-star-empty glyphicon-star'); });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM