jQuery实现单击某个标签改变样式

2019-01-02 21:36发布

1、HTML代码,如下图:

<p class="sc_member_recharge_form">
     <span class="selected">20元</span>
     <span >50元</span>
     <span >100元</span>
     <span >200元</span>
     <span >300元</span>
     <span >其它金额</span>
</p>

2、jQuery代码,如下图:

<script>
    $(document).ready(function(){
        $(".sc_member_recharge_form span").click(function(){
            var select = $(this).text();
            if(select === 'other amount' || select === '其它金额'){
                $(".sc_member_recharge_form span").removeClass("selected");
                $(this).addClass("selected");
            }else{
                $(".sc_member_recharge_form span").removeClass("selected");
                $(this).addClass("selected");
            }

        });
    });
</script>

 

文章来源: https://www.cnblogs.com/phperlinxinlan/p/10186563.html
标签: