【问题标题】:cakephp get element value js helpercakephp获取元素值js助手
【发布时间】:2013-04-02 05:20:52
【问题描述】:

我是 CakePHP 的初学者,并尝试搜索这个问题,但没有任何收获。 我有一个选择按钮,当用户选择一个选项时,我必须触发一个事件并将所选值传递给控制器​​的操作。 代码如下:


<?php
//I only need a select button why to bother of creating form
echo $this->Form->input('district',array('label'=>'labelhere','id'=>'idhere'));

//script handler for select option
$this->Js->get('#idhere');
$this->Js->event(
        'change',
        $this->Js->request(
            array('action' => 'listing',<the selected value of #idhere here>),
            array('async' => true,
                'method'=>'POST',
                'update' => '#HFNames')
        )
    );

?>
<div id="HFNames">
Div to include ajax returns.
</div>

确切地说, Jquery 的 $('selector').value(); 的 CakePHP 等价物是什么?

这是生成的Html代码:

<html>
<div class="input select"><label for="idhere">labelhere</label><select  name="data[district]" id="idhere">
<option value="01">Bhojpur</option>
<option value="02">Dhankuta</option>
<option value="03">Ilam</option>
<option value="04">Jhapa</option>
<option value="05">Khotang</option>
<option value="06">Morang</option>
<option value="07">Okhaldhunga</option>
<option value="08">Panchthar</option>
<option value="09">Sankhuwasabha</option>
<option value="10">Saptari</option>
<option value="11">Siraha</option>
</select></div>
</html>

【问题讨论】:

  • 给出输入的html源代码。
  • echo $this-&gt;Form-&gt;input('district',array('label'=&gt;'labelhere','id'=&gt;'idhere'));生成哪个html

标签: php jquery cakephp helper


【解决方案1】:

试试这个

<?php
//I only need a select button why to bother of creating form
echo $this->Form->input('district',array('label'=>'labelhere','id'=>'idhere'));

//script handler for select option
$this->Js->get('#idhere');
$this->Js->event(
        'change',
        $this->Js->request(
            array('action' => 'listing'),
            array('async' => true,
                'method'=>'POST',
                'update' => '#HFNames',
                'data'   => '$("selector").value()')
        )
    );

?>
<div id="HFNames">
Div to include ajax returns.
</div>

抽出时间阅读这篇文章:Dynamic Web With Cake

【讨论】:

  • var_dump($this-&gt;request-&gt;data) 在您的function listing 中查看数据的来源。
猜你喜欢
  • 1970-01-01
  • 2012-03-03
  • 1970-01-01
  • 1970-01-01
  • 2012-08-09
  • 2014-01-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多