首页 > 解决方案 > 隐藏复选框的标签 - Yii2

问题描述

我想知道如何在js中使用hide()隐藏复选框的标签,现在我可以隐藏复选框,但是我试图禁用标签,它不起作用。

<?= $form->field($modelQuestion, "[{$indexQuestion}]justificar_respuesta")->checkbox(array(
                                            'label'=>'',
                                            'labelOptions'=>array('style'=>'padding:5px;'),
                                            ))->label('You want a response justified ?');?>

js

标签: javascriptyii2

解决方案


我不知道 js 这样做有什么意义,但是,您可以这样处理:

id为您的复选框定义属性:

<?= $form->field($modelQuestion, "[{$indexQuestion}]justificar_respuesta")->checkbox(['id' => 'myId', 'labelOptions' => ['style'=>'padding:5px;']])->label('You want a response justified ?');?>

和 jQuery:

$("label[for='myId']").contents().filter(function(){
    return (this.nodeType == 3);
}).remove();

推荐阅读