zoukankan      html  css  js  c++  java
  • 对一些img标签的切换功能实现,有更好的方式吗吗吗

    var iosSelect = true, androidSelect = true, windowsSelect = true, allSelect = true;
        $(function () {
            
            $("#ios").click(function () {
                if (iosSelect) {
                    $("#ios").attr("src", "/Content/images/icon/icon_Remember2.png");
                    iosSelect = false;
                } else {
                    $("#ios").attr("src", "/Content/images/icon/icon_Remember3.png");
                    iosSelect = true;
                }
            });
            $("#android").click(function () {
                if (androidSelect) {
                    $("#android").attr("src", "/Content/images/icon/icon_Remember2.png");
                    androidSelect = false;
                } else {
                    $("#android").attr("src", "/Content/images/icon/icon_Remember3.png");
                    androidSelect = true;
                }
            });
            $("#windows").click(function () {
                if (windowsSelect) {
                    $("#windows").attr("src", "/Content/images/icon/icon_Remember2.png");
                    windowsSelect = false;
                }
                else {
                    $("#windows").attr("src", "/Content/images/icon/icon_Remember3.png");
                    windowsSelect = true;
                }
            });
            $("#all").click(function () {
                if (allSelect) {
                    $("#all").attr("src", "/Content/images/icon/icon_Remember2.png");
                    $("#ios").attr("src", "/Content/images/icon/icon_Remember2.png");
                    $("#android").attr("src", "/Content/images/icon/icon_Remember2.png");
                    $("#windows").attr("src", "/Content/images/icon/icon_Remember2.png");
                    allSelect = false;
                    iosSelect = false;
                    androidSelect = false;
                    windowsSelect = false;
                }
                else {
                    $("#all").attr("src", "/Content/images/icon/icon_Remember3.png");
                    $("#ios").attr("src", "/Content/images/icon/icon_Remember3.png");
                    $("#android").attr("src", "/Content/images/icon/icon_Remember3.png");
                    $("#windows").attr("src", "/Content/images/icon/icon_Remember3.png");
                    allSelect = true;
                    iosSelect = true;
                    androidSelect = true;
                    windowsSelect = true;
                }
    
            });
    
        });

    效果图:

    切换后:

    那么多重复代码。。。有更好的方式吗?

  • 相关阅读:
    LightOJ 1313
    LightOJ 1285
    [坑] treap
    HDU 4511 小明系列故事——女友的考验 (AC自动机+DP)
    ZOJ 3765 Lights (伸展树splay)
    HDU 4818 RP problem (高斯消元, 2013年长春区域赛F题)
    SGU 104. Little shop of flowers (DP)
    HDU 3472 HS BDC (混合图的欧拉路径判断)
    POJ 1386 Play on Words (有向图欧拉路径判定)
    微信小程序上架需要增值电信业务经营许可证ICP?
  • 原文地址:https://www.cnblogs.com/Benjamin/p/2888168.html
Copyright © 2011-2022 走看看