将onclick事件应用于选项

时间:2012-09-05 11:35:06

标签: php zend-framework onclick mootools zend-form

我使用zend表单来创建表单。我也在使用mootools for javascript。

$this->addElement('radio', 'alone', array(
    'label' => 'Are you going to be taking part with anyone else?',
    'required' => true,
    'onClick' => 'showFields();',
    'multiOptions' => array(
        'yes' => 'Yes',
        'no' => 'No'
    ))
);

目前,如果选择任何选项,onclick事件将起作用。我如何才能让它被选中?

1 个答案:

答案 0 :(得分:1)

你可以试试这个......

$this->addElement('radio', 'alone', array(
    'label' => 'Are you going to be taking part with anyone else?',
    'required' => true,
    'onClick' => 'showFields(this);',
    'multiOptions' => array(
        'yes' => 'Yes',
        'no' => 'No'
    ))
);

在你的功能......

function showFields(elem)
{
    if(elem.value != 'yes')
        return false;

    // rest of the code
}
相关问题