如何减少具有相同功能但不同事件的 Jquery 代码

How can I reduce Jquery code with the same functionality, but different events

如何减少这段代码?他们做同样的事情,如果两个选择中的任何一个都没有值,则禁用按钮。

    //Evento de submenu Canal
    $(document).on('change','select[name="grupoCanalSubMenu"]',function(){
        if (($('select[name="grupoCanalSubMenu"]').children("option:selected").val() == '') || ($('select[name="canalSubMenu"]').children("option:selected").val() == '')) {
            $('#new-usuario-registrar-canal').attr("disabled", true);
        } else{
            $('#new-usuario-registrar-canal').attr("disabled", false);
        }
    });

    //Evento de submenu Canal
    $(document).on('change','select[name="canalSubMenu"]', function(){

        if (($('select[name="grupoCanalSubMenu"]').children("option:selected").val() == '') || ($('select[name="canalSubMenu"]').children("option:selected").val() == '')) {
            $('#new-usuario-registrar-canal').attr("disabled", true);
        } else{
            $('#new-usuario-registrar-canal').attr("disabled", false);
        }
    });

只需使用 css 的逗号分隔符即可添加另一个选择器。

//Evento de submenu Canal
$(document).on('change','select[name="grupoCanalSubMenu"], select[name="canalSubMenu"]',function(){
    if (($('select[name="grupoCanalSubMenu"]').children("option:selected").val() == '') || ($('select[name="canalSubMenu"]').children("option:selected").val() == '')) {
        $('#new-usuario-registrar-canal').attr("disabled", true);
    } else{
        $('#new-usuario-registrar-canal').attr("disabled", false);
    }
});