【问题标题】:Add tabs to form using jQuery (cakephp 2.1)使用 jQuery (cakephp 2.1) 向表单添加标签
【发布时间】:2012-05-09 21:08:27
【问题描述】:

我正在使用 cakephp 2.1 就好了;我想使用 jquery 让我的表单按标签划分。 已经在蛋糕外使用了 jquery 并让标签演示工作。 http://jqueryui.com/demos/tabs/
我还让 jquery 可用于 webroot 文件夹中的 cakephp 和

ProjectsController.php

public $helpers = array('Js' => array('Jquery'));

add.ctp(在最后一行)

echo $this->Js->writeBuffer(); // Write cached scripts

我应该在哪里以及如何在我的视图中调用 jquery?我知道我应该使用类似于演示的东西:

<script>
        $(function() {
            $( "#tabs" ).tabs();
        });
    </script>

但不知道在我看来在哪里做它和sintax。

谁能帮忙?

非常感谢!

这如果我的完整 add.ctp

<div class="projects form">
<?php echo $this->Form->create('Project');?>

<fieldset>
    <legend><?php echo __('Add Project'); ?></legend>
<?php
            $arr_pr_subject = Configure::read('AR_SUBJECT'); 
            $arr_pr_status = Configure::read('AR_STATUS'); 
            $arr_pr_payment = Configure::read('AR_PAYMENT'); 
            $arr_pr_country = Configure::read('AR_COUNTRY'); 
            echo $this->Form->input('name', array('label' => 'Name:'));
            echo $this->Form->input('pr_subject', array('label' => 'Subject:', 'options' => $arr_pr_subject));
            echo $this->Form->input('pr_country', array('label' => 'Country:', 'options' => $arr_pr_country));
            echo $this->Form->input('pr_number', array('label' => 'ASC Project Number:'));
            echo $this->Form->input('pr_status', array('label' => 'Status:', 'options' => $arr_pr_status));
            echo $this->Form->input('client_id', array('label' => 'Client:', 'options' => $clients));
            echo $this->Form->input('pr_client_number', array('label' => 'Client Project Number:'));
            echo $this->Form->input('exec_id', array('label' => 'Sales Executive:', 'options' => $execs));
            echo $this->Form->input('pr_start', array('label' => 'Est. Start Date:'));
            echo $this->Form->input('pr_end', array('label' => 'Est. End Date:'));
            echo $this->Form->input('pr_notes', array('label' => 'Notes:'));
            echo $this->Form->input('pr_payment', array('label' => 'Payment options:', 'options' => $arr_pr_payment));
?>
</fieldset>
<?php echo $this->Form->end(__('Submit'));?>
</div>
<?php
echo $this->Js->writeBuffer(); // Write cached scripts
?>

【问题讨论】:

    标签: php jquery cakephp-2.1


    【解决方案1】:

    在您的&lt;head&gt; 中,包括 jquery 和 jqueryui:

    <script src="/js/path/to/jquery.js" type="text/javascript"></script>
    <script src="/js/path/to/jqueryui.js" type="text/javascript"></script>
    

    然后在它下面,包含一个单独的js文件来保存你所有的代码

    &lt;script src="/js/myscripts.js" type="text/javascript"&gt;&lt;/script&gt;

    在该文件 (myscripts.js) 中放入您的 jQuery 代码:

    $(function() {
      $( "#tabs" ).tabs();
    });
    

    然后构建表单输入以匹配 jQuery Tabs 语法

    <form action="...">
    <div id="tabs">
      <ul>
        <li><a href="#tab1">Tab 1</a></li>
        <li><a href="#tab2">Tab 2</a></li>
      </ul>
      <div id="tab1">
        <!-- Tab 1 inputs in here -->
      </div>
      <div id="tab2">
        <!-- Tab 2 inputs here -->
      </div>
    </div>
    </form>
    

    【讨论】:

    • 谢谢凯尔!但是,您的示例似乎没有处理 cakephp。就像你建议的那样,我已经在蛋糕外面做了 jquery 标签。我的问题是我不知道如何以我的 cakehpp 形式进行操作。你能帮忙把这个放在蛋糕上吗?我已经按照说明准备 cakephp 以使用 jquery,只是不知道如何为我的表单实际实现选项卡。非常感谢请帮忙。卡洛斯
    • 啊,是的,请原谅我。前段时间离开PHP,给出了普遍的答案。
    • 我认为答案是不言自明的,即使没有 CakePHP 代码示例。只需在
    • 谢谢鲍里斯拉夫;你是绝对正确的。昨天早些时候,我不知道如何将此解决方案合并到我的 cakephp 表单中。然后它点击我从我的 .ctp 视图中删除所有内容并从此处的解决方案构建表单,与 jqueryui.com/demos/tabs 相同,它工作得很好,非常重要的是我更好地掌握了如何整合事物。今天的第一件事是选择 Kyle 的答案,并附上关于我自己的蛋糕初学者的集成说明。最好的问候,并感谢您的大力帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-08
    • 2012-04-30
    • 1970-01-01
    相关资源
    最近更新 更多