你能把这段代码改成jquery吗?



>我需要帮助将纯javascript代码更改为jquery代码

document.getElementById('type').onchange = function (){
        if(this.value == "Student"){
            $("#cls").prop({disabled: false});
            $("#sec").prop({disabled: false});
            $('.cls').show();
            $('.sec').show();
            }
            else{
                $("#cls").prop({disabled: true});
                $("#sec").prop({disabled: true});
                $('.cls').hide();
                $('.sec').hide();
            }
    }  

这主要是jQuery。话虽如此,你可以减少一点。

$('#type').on('change', function (){
    if (this.value == "Student"){
        $("#cls, #sec").prop({disabled: false});
        $('.cls, .sec').show();
    } else{
        $("#cls, #sec").prop({disabled: true});
        $('.cls, .sec').hide();
    }
});

最新更新