2016-01-14 28 views
0

这是我在yii2如何在yii自定义单选按钮中设置onclick事件?

<?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); 

?> 

HTML代码中的自定义单选按钮如何设置这个自定义单选按钮的onclick事件?

回答

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); 

?> 
+0

大,帮我.. !! –

+0

在这种情况下,如果我警告(this.id)它显示div id,我如何选择单选按钮值? –

+0

使用javascript val()函数 – Bfcm

相关问题