【问题标题】:cakephp jquery onclick alert boxcakephp jquery onclick 警告框
【发布时间】:2014-01-26 17:23:05
【问题描述】:

我有一个带有选择输入的表单。我想在选择下拉列表时显示警报。 观点:

<?php
echo $this->Form->create('Office');
echo $this->Form->input('under_office', array('type' => 'select', 'options' => $settings,'empty'   => false));
echo $this->Form->end('Save');
?>

控制器

public function add() {


    $settings = $this->Office->Officetype->find('list', array('fields'=> array('Officetype.id', 'Officetype.name')
    ));
      $this->set(compact('settings'));

        if ($this->request->is('post')) {
            $this->Office->create();
            $post_data = $this->request->data;
            if ($this->Office->save($post_data)) {
                $this->Session->setFlash(__('Office details saved successfully'));
                return $this->redirect(array('action' => 'add'));
            }
            $this->Session->setFlash(__('Unable to save Office details'));
        }
  }

【问题讨论】:

    标签: javascript jquery cakephp-2.4


    【解决方案1】:

    这可能对你有帮助,首先在你的选择标签上放一些 id。

    echo $this->Form->input('under_office', array('type' => 'select', 'id' => 'myselect', 'options' => $settings,'empty'  => false));
    

    在执行上述代码之后,将下面的代码放在&lt;script&gt; &lt;/script&gt;标签之间或您的javascript存在的地方,

    document.getElementById('myselect').onchange = function (){
        alert('hello guys');
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-03
      • 1970-01-01
      • 1970-01-01
      • 2015-03-15
      • 2013-10-28
      • 2011-08-17
      • 1970-01-01
      • 2014-06-08
      相关资源
      最近更新 更多