我尝试隐藏/显示一个组合框,我有2个组合框,我希望第二个组合框一直隐藏到第一个更改为止。

<?php echo $this->Form->input('combobox1'); ?>
<?php echo $this->Form->input('combobox2'); ?>


所以我想我需要做些类似的事情:

$this->Js->get('#idcombobox2')->effect('hide');隐藏页面刚加载时的组合框。

和类似的东西:

$this->Js->get('#idcombo1')->event('change', $this->Js->get('#idcombobox2')->effect('show'));原因是第一个更改我想显示第二个。

但这行不通。

谢谢你的帮助。

最佳答案

您是否在视图中包括jquery或其他框架?

echo $this->Html->script('//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js');


如果要使用<head>将其输出到array('inline' => false),请确保在布局中指定脚本位置:

echo $scripts_for_layout;


记住,您还需要在视图中输出缓冲区:

echo $this->Js->writeBuffer();


编辑:实际为我工作的代码:

$event = $this->Js->get('#combo2')->effect('show');
$this->Js->get('#combo1')->event('change', $event);


编辑2:我以某种方式只是使用scriptBlock隐藏combo2。所以整个代码会像这样

$hide = $this->Js->get('#combo2')->effect('hide');
echo $this->Html->scriptBlock($this->Js->domReady($hide));
$show = $this->Js->get('#combo2')->effect('show');
$this->Js->get('#combo1')->event('change', $show);
echo $this->Js->writeBuffer(array('inline' => false));

10-05 20:44
查看更多