kohana表单帮助程序包括javascript



我使用kohana-helper在视图中创建表单,但我需要在某些字段中包含一些javascript(如onclick、onblur等)。我怎么能做到这一点而不放弃kohana形式的帮助?

例如,在纯html中,我有:

               <input class="field" type="text" id="email" name="email" value="<?php if (Cookie::get('email')) echo Cookie::get('email'); else echo 'Adresă Email'; ?>" onclick="if (this.value=='Adresă Email') this.value='';" onblur="if (this.value=='') this.value='Adresă Email';" />

并使用表单助手:

            <?php echo Form::input('email', $email_value , array('id'=>'email', 'class'=>'field',$validator['email'])) ?>

这是可以的,但我也想添加onclick和onblur。你知道怎么做吗?谢谢

只需在属性数组中添加onclick、onblur:

echo Form::input('email', $email_value, array('onlick' => 'something;', 'onblur' => 'something else;'))

或者考虑使用jQuery并停止担心内联属性;)

最新更新