完善版二级联动(可作为函数)需要导入jquery

<select class="form-control select_parent"  name="type_name_1"   >
                                        <option >请选择</option>
                                            <option value="集体活动">早操、组织生活和必须参加的集体活动</option>
                                            <option value="违反纪律">违反规章制度,社会道德规范,党团纪律(受多重处分的按照最高级别扣分)</option>
                                            <option value="干部失职">学生干部不履行职责</option>
                                        </select>
<select class="form-control select_child"  name="type_name_child_1"  >
<script>
$(function(){
    var val_json='{"集体活动":["不经请假而缺席(每次扣2分)","迟到或早退(每次扣0.5分)"],"违反纪律":["院系通报批评(6分)","学校通报批评(8分)","受警告处分(15分)","受严重警告处分(20分)","受记过处分(30分)","受留校察看处分(40分)","受开除党团籍处分(50分)"],"干部失职":["酌情扣除(1分)","酌情扣除(2分)","酌情扣除(3分)","酌情扣除(4分)","酌情扣除(5分)"]}';
    var val_obj=eval('('+val_json+')');
    $(".select_parent").change(function(){
        var now_select=$(this).val();
        alert(now_select);
        $(".select_child").html('<option value="">请选择</option>');
        for(var k in val_obj[now_select])
        {
            var now_child=val_obj[now_select][k];
            $(".select_child").append('<option value="'+now_child+'">'+now_child+'</option>');
        }
    });
});
</script>

 

posted @ 2021-01-24 17:27  博二爷  阅读(55)  评论(0编辑  收藏  举报