Php 将onclick事件应用于选项
我正在使用zend form创建一个表单。我也在使用mootools来编写javascriptPhp 将onclick事件应用于选项,php,zend-framework,onclick,mootools,zend-form,Php,Zend Framework,Onclick,Mootools,Zend Form,我正在使用zend form创建一个表单。我也在使用mootools来编写javascript $this->addElement('radio', 'alone', array( 'label' => 'Are you going to be taking part with anyone else?', 'required' => true, 'onClick' => 'showFields();', 'multiOptions' =&
$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
}
在执行任何其他操作之前,请先验证
showFields()
函数的第一行是否选中了yes
。尝试此解决方案时,我遇到以下错误:Uncaught TypeError:无法读取未定义的属性“value”
使用id而不是value对该问题进行排序。但是,当页面加载时,将显示要隐藏的字段。但是,当我单击“否”时,它们会消失