简体   繁体   English

如何切换多个字体图标

[英]How to Toogle Multiple Font Icons

I followed this to create Custom Font Icons and Added the links in my Code over there I have Created Icons form SVG and added Custom Names 我按照此步骤创建了自定义字体图标,并在代码中添加了链接,在那儿我以SVG形式创建了图标并添加了自定义名称

In my Code I have Multiple Buttons and Multiple ' 在我的代码中,我有多个按钮和多个'

Now I am using all 3 icons like this 现在我正在使用所有3个这样的图标

<div class="col-sm-10 col-sm-offset-1">
    <a class="btn1"><i class="ic-like"></i></a>
    <a class="btn2"><i class="ic-dislike"></i></a>
    <a class="btn3"><i class="ic-happy"></i></a>
</div>

Now I have 3 Icons Should Toogle in my Code 现在我的代码中应该有3个图标

So I have Given this in my Code to Toogle icons 所以我已经在我的代码中给出了此图标

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script>
$(document).ready(function(){
    $("a").click(function(){
        $("i").toggleClass("ic-like2");
    });
   $("a").click(function(){
        $("i").toggleClass("ic-dislike2");
    });
   $("a").click(function(){
        $("i").toggleClass("ic-happy2");
    });


});
</script>

My icon names are 'ic-like,ic-like2,ic-dislike,ic-dislike2,ic-happy,ic-unhappy2' 我的图标名称是“ ic样,ic样2,ic不喜欢,ic不喜欢2,ic快乐,ic不快乐2”

But Now Problem is that when I open The Page all the icons are toogled to ic-like2 但是现在的问题是,当我打开“页面”时,所有图标都切换为ic-like2

and when I click its back to normal 'ic-like' 当我点击它返回正常的“ ic-like”

but I want to show 'ic-like' and on click it should toogle 'ic-like2' 但我想显示“ ic-like”,然后单击它就可以显示“ ic-like2”

can any one suggest me on this kind I cant give in button and 'a' tag here almost all other divs are using same tags in bootstrap they are many So I need to give for these 3 only without changing other If I give in Button its loading other Css in 'a' tag also its loading other css 有谁能建议我这种方式,我不能给按钮和'a'标签吗?几乎所有其他div在引导程序中都使用相同的标签,它们很多,所以我只需要为这3个给定,而无需更改其他选项。在'a'标签中加载其他CSS也在加载其他CSS

Update 更新资料

Now When I onclick on any of the 3 icons except these 3 the icons which are there in <a are switching blank 现在,当我单击除这三个图标之外的三个图标中的任何<a<a中的图标切换为空白

can any one suggest me how to turn this off 有人可以建议我如何关闭此功能

You can so something like this. 您可以这样做。 You need to use jquery find selector function for this. 您需要为此使用jquery find选择器功能。

 $(document).ready(function(){ $("a.btn1").click(function() { $(this).find("i").toggleClass("fa-thumbs-o-up fa-thumbs-o-down"); }); $("a.btn2").click(function(){ $(this).find("i").toggleClass("fa-smile-o fa-frown-o"); }); $("a.btn3").click(function(){ $(this).find("i").toggleClass("fa-unlock fa-unlock-alt"); }); }); 
 .fa { font-size: 58px !important; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css" /> <div class="col-sm-10 col-sm-offset-1"> <a class="btn1"><i class="fa fa-thumbs-o-up"></i></a> <a class="btn2"><i class="fa fa-smile-o"></i></a> <a class="btn3"><i class="fa fa-unlock"></i></a> </div> 

Hi this might help full to you 嗨,这可能对您有所帮助

    $(".btn1 > i").click(function(){
        $(this).toggleClass("ic-like2 ic-like");
    });
   $(".btn2 > i").click(function(){
        $(this).toggleClass("ic-dislike2 ic-dislike");
    });
   $(".btn3 > i").click(function(){
        $(this).toggleClass("ic-happy2 ic-happy");
    });

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

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