2 liangzhijun0325 LiangZhijun0325 于 2017.09.02 16:54 提问

把以下两级连选的代码,写成三级连选(谢谢)q、跪求各位大神帮忙 3C
 function typecheck(v, i, t) {
        if ($("input[type=checkbox][name=" + t + "]:checked").length == 0) 
        {
            $("input[type=checkbox][name=" + t + "]").removeClass("checkSpan");
            $("span[name=" + t + "]").removeClass("checkSpan");
            $("input[type=checkbox][name=" + t + "]").attr("disabled", false);
        }
        else {
            switch (v.val()) {
                                         case "0001": case "0002":
                    $("input[type=checkbox][name=" + t + "]:gt(1)").attr("disabled", true);
                    $("input[type=checkbox][name=" + t + "]:gt(1)").addClass("checkSpan");
                    $("span[name=" + t + "]:gt(1)").addClass("checkSpan");

                    $("input[type=checkbox][name=" + t + "]:eq(0)").removeClass("checkSpan");
                    $("input[type=checkbox][name=" + t + "]:eq(1)").removeClass("checkSpan");

                    $("span[name=" + t + "]:eq(0)").removeClass("checkSpan");
                    $("span[name=" + t + "]:eq(1)").removeClass("checkSpan");

                    $("input[type=checkbox][name=" + t + "]:gt(1)").attr("checked", false);
                    break;

                case "0003": case "0004":
                    $("input[type=checkbox][name=" + t + "]:gt(3)").attr("disabled", true);
                    $("input[type=checkbox][name=" + t + "]:gt(3)").addClass("checkSpan");
                    $("input[type=checkbox][name=" + t + "]:lt(2)").attr("disabled", true);
                    $("input[type=checkbox][name=" + t + "]:lt(2)").addClass("checkSpan");
                    $("span[name=" + t + "]:gt(3)").addClass("checkSpan");
                    $("span[name=" + t + "]:lt(2)").addClass("checkSpan");


                    $("input[type=checkbox][name=" + t + "]:eq(3)").removeClass("checkSpan");
                    $("input[type=checkbox][name=" + t + "]:eq(2)").removeClass("checkSpan");
                    $("span[name=" + t + "]:eq(3)").removeClass("checkSpan");
                    $("span[name=" + t + "]:eq(2)").removeClass("checkSpan");

                    $("input[type=checkbox][name=" + t + "]:gt(3)").attr("checked", false);
                    $("input[type=checkbox][name=" + t + "]:lt(2)").attr("checked", false);
                    break;
                case "0005": case "0006":
                    $("input[type=checkbox][name=" + t + "]:gt(5)").attr("disabled", true);
                    $("input[type=checkbox][name=" + t + "]:gt(5)").addClass("checkSpan");
                    $("input[type=checkbox][name=" + t + "]:lt(4)").attr("disabled", true);
                    $("input[type=checkbox][name=" + t + "]:lt(4)").addClass("checkSpan");
                    $("span[name=" + t + "]:gt(5)").addClass("checkSpan");
                    $("span[name=" + t + "]:lt(4)").addClass("checkSpan");


                    $("input[type=checkbox][name=" + t + "]:eq(5)").removeClass("checkSpan");
                    $("input[type=checkbox][name=" + t + "]:eq(4)").removeClass("checkSpan");
                    $("span[name=" + t + "]:eq(5)").removeClass("checkSpan");
                    $("span[name=" + t + "]:eq(4)").removeClass("checkSpan");

                    $("input[type=checkbox][name=" + t + "]:gt(5)").attr("checked", false);
                    $("input[type=checkbox][name=" + t + "]:lt(4)").attr("checked", false);
                    break;
                                         }

        }
        initLevel();
    }
    function initLevel() {
        var NowLatinLevel = $("#NowLatinLevel").val(), NowLevel = $("#NowInternationalLevel").val();
        var reg = /^0{1,}/;
        if (NowLatinLevel != "" && NowLatinLevel != null && /^\d{4}$/.test(NowLatinLevel)) {
            NowLatinLevel = NowLatinLevel.replace(reg, "");
            initLevelOther(NowLatinLevel, "L");
        }
        if (NowLevel != "" && NowLevel != null && /^\d{4}$/.test(NowLevel)) {
            NowLevel = NowLevel.replace(reg, "");
            initLevelOther(NowLevel, "S");
        }
    }
    function initLevelOther(v, t) {
        $("input[type=checkbox][name=" + t + "]").attr("disabled", true);
        $("input[type=checkbox][name=" + t + "]").addClass("checkSpan");
        $("span[name=" + t + "]").addClass("checkSpan");
        v = Number(v);
        switch (v) {
            case 1: case 3: case 5: case 6: case 7: case 8:
                $("input[type=checkbox][name=" + t + "]:eq(" + v + ")").attr("disabled", false);
                $("input[type=checkbox][name=" + t + "]:eq(" + v + ")").removeClass("checkSpan");
                $("span[name=" + t + "]:eq(" + v + ")").removeClass("checkSpan");
                break;
            case 2: case 4:
                $("input[type=checkbox][name=" + t + "]:eq(" + v + ")").attr("disabled", false);
                $("input[type=checkbox][name=" + t + "]:eq(" + (v + 1) + ")").attr("disabled", false);
                $("input[type=checkbox][name=" + t + "]:eq(" + v + ")").removeClass("checkSpan");
                $("span[name=" + t + "]:eq(" + v + ")").removeClass("checkSpan");
                $("input[type=checkbox][name=" + t + "]:eq(" + (v + 1) + ")").removeClass("checkSpan");
                $("span[name=" + t + "]:eq(" + (v + 1) + ")").removeClass("checkSpan");
                break;
        }

    }

1个回答

showbo
showbo   Ds   Rxr 2017.09.02 20:36
Csdn user default icon
上传中...
上传图片
插入图片