将onclick事件应用于某个选项


apply onclick event to an option

我使用zend表单来创建表单。我还使用javascript的mootools。

$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事件都会起作用。我如何让它在被选中时起作用?

你可以试试这个。。。

$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
}