2011-11-23 124 views
0

我不知道为什么这onChange事件不起作用。也许我已经习惯了代码,我看不出我的错误。我会感激你的帮助:CakePHP onChange事件

<td class="cellInput"> 
    <?php 
    $options = array('200'=>'200', '500'=>'500', '1000'=>'1000', '2000'=>'2000', '5000'=>'5000', 'Outro'=>'Outro'); 
    $attributes = array('legend' => false); 

    echo $form->select('capacidade', $options, array(
     'class' => '', 
     'label' => '', 
     'default' => '200', 
     'onchange' => "javascript:checkForOther(this);", 
    )); 
    ?> 
</td> 
+2

你应该尝试并接受回答您以前的问题。 – abhinav

回答

0

尝试

  1. 把属性作为第四个参数,而不是第三:

    echo $form->select('capacidade', $options, null, 
        array(
         'class'=>'' 
         ,'label' => '' 
         ,'default' => '200' 
         ,'onchange' => "javascript:checkForOther(this);" 
        ) 
    ); 
    
  2. 是否生成页面的源代码有onChange属性?

  3. documentation
+0

太棒了!非常感谢你们所有人!它做了工作=) –

0

CakePHP documentation on select method,第三个参数是用来选择哪个选项是默认选中。

必须使用第四个参数通过HTML属性添加到select元素:

<td class="cellInput"> 
    <?php 
    $options = array('200'=>'200', '500'=>'500', '1000'=>'1000', '2000'=>'2000', '5000'=>'5000', 'Outro'=>'Outro'); 
    $attributes = array('legend'=>false); 
    echo $form->select('capacidade', $options, '200', array('class'=> '', 'label' => '', 'onchange' => "checkForOther(this);")); 
    ?> 
</td> 
2

正如其他人建议,将属性的正确参数位置。另一件事我会做的是去除javascript和刚刚具备的功能名称存在,如:

来源:'onchange' => "javascript:checkForOther(this);"

要:'onchange' => "checkForOther(this)"