[英]How to customise outer div when creating radioList in Yii framework 2?
下面是生成radiolist的我的引導活動字段。
<?= $form->field($model, 'photo_id')->radioList(['A', 'B', 'C']) ?>
上面的代碼生成以下 HTML 標記。
<div id="model-photo_id">
<div class="radio">
<label>
<input type="radio" name="Model[photo_id]" value="0" checked="">
A
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="Model[photo_id]" value="1" checked="">
B
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="Model[photo_id]" value="2" checked="">
C
</label>
</div>
</div>
目標是<div class="radio">
。 我想通過更改類名或添加更多類名來自定義這個 div,在這個div
中添加更多屬性等。 我怎樣才能做到這一點?
您可以嘗試使用此自定義模板,而不是將類應用於單選 div,您也可以將類應用於標簽
echo $form->field($model, 'photo_id')
->radioList(
[0 => 'A', 1 => 'B', 2 => 'C'], [
'item' => function($index, $label, $name, $checked, $value) {
$return = '<label class="modal-radio">';
$return .= '<input type="radio" name="' . $name . '" value="' . $value . '" tabindex="3">';
$return .= '<i></i>';
$return .= '<span>' . ucwords($label) . '</span>';
$return .= '</label>';
return $return;
}
]
)
->label(false);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.