Cakephp 2.x - 隐藏/显示组合框

Cakephp 2.x - hide/show a combobox

本文关键字:显示 组合 隐藏 Cakephp      更新时间:2023-09-26

我尝试隐藏/显示一个组合框,我有 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');

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

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));