Yii2-如何从DepDrop获取所选值

Yii2-如何从DepDrop获取所选值,yii2,selected,Yii2,Selected,我使用这个模块 这是我的代码: <?php $this->registerJs(' $(\'select[id="sub_name"]\').change(function(){ if ($(\'option:selected\').val() == 3) document.getElementById("table").style.display = "block"; else document.getElementById("t

我使用这个模块 这是我的代码:

 <?php $this->registerJs(' $(\'select[id="sub_name"]\').change(function(){

    if ($(\'option:selected\').val() == 3)

       document.getElementById("table").style.display = "block";
    else 
       document.getElementById("table").style.display = "none";

    });', View::POS_READY);
    ?>
_表格:

<?= $form->field($model, 'categories')->dropDownList($catList, ['id'=>'cat_name', 'prompt'=>'Select category']);?>

<?= $form->field($model, 'subcategories')->widget(DepDrop::classname(), [
            'options'=>['id'=>'sub_name'], 
            'pluginOptions'=>[
            'depends'=>['cat_name'],
            'placeholder'=>'Select subcategory',
            'url'=>  Url::to(['ad/subcat'])
            ]
            ]);  ?>
它工作正常,但我想根据所选的子类别显示或隐藏DIV

这是我的代码: 这是我的代码:

 <?php $this->registerJs(' $(\'select[id="sub_name"]\').change(function(){

    if ($(\'option:selected\').val() == 3)

       document.getElementById("table").style.display = "block";
    else 
       document.getElementById("table").style.display = "none";

    });', View::POS_READY);
    ?>

但它不起作用,它从类别下拉列表中获取值。 如何从所选子类别中获取值