这是我在yii2中的自定义单选按钮的Html
<?php
echo $form->field($ProductShipping, 'id_shipping')->radioList(
['1'=>'Free', '2'=>'Pickup','3'=>'Country Wise','4'=>'API'],
['item' => function($index, $label, $name, $checked, $value) {
$return = '<label class="radio">';
$return .= '<input type="radio" name="' . $name . '" value="' . $value . '">';
$return .= '<label>' . ucwords($label) . '</label>';
$return .= '</label>';
return $return;
}
]
)->label(false);
?>
如何在此自定义单选按钮中设置onclick事件?
答案 0 :(得分:2)
您可以按照以下方式实施:
<?php
echo $form->field($ProductShipping, 'id_shipping')->radioList(
['1'=>'Free', '2'=>'Pickup','3'=>'Country Wise','4'=>'API'],
['item' => function($index, $label, $name, $checked, $value) {
$return = '<label class="radio">';
$return .= '<input type="radio" name="' . $name . '" value="' . $value . '">';
$return .= '<label>' . ucwords($label) . '</label>';
$return .= '</label>';
return $return;
},
'onclick' => "alert('test')"
]
)->label(false);
?>