CHtml:image如何使用onload事件

如题,我在载入图片的时候,需要执行图片的宽度控制的JS,应该怎么调用?

public static function image($src,$alt=’’,$htmlOptions=array())

在 $htmlOptions 传入 onload方法即可~

CHtml::image("/uploads/images/".$data->ppic, $data->pid, array(

‘width’ => 120,‘height’ => 120, ‘class’ => ‘image’,

‘onload’ => ‘DrawImage(this,120,120)’,

);

我是这么操作的,但是页面上并没有onload

把生成的html贴出来看看~

html代码就是

<img width=“120” hight=“120” src="…" class=‘image’ />

就是没有onload

echo CHtml::image("/uploads/images/".$data->ppic, $data->pid, array(‘width’ => 120,‘height’ => 120, ‘class’ => ‘image’,‘onload’ => ‘DrawImage(this,120,120)’)); --试试这个

貌似跟我写的代码没有区别吧

最简单的方法 就是用JQ。。。。。。

仔细看看 你少了个括号 ! 所以你没有生成 onload="DrawImage(this,120,120)"