使用jquery的选项卡加载2次简单的codeigniter视图

时间:2013-04-08 12:00:46

标签: php jquery codeigniter

我有一个带有jquery选项卡的标题(视图),它将成为我项目的“模板”。但是,我的标题和内容总是显示两次。这是屏幕截图(取自您在下面看到的控制器):

enter image description here

这是我的标题视图:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Johanes Indra</title>
<link rel="stylesheet" href="<?php echo base_url(); ?>jquery/jquery-ui-1.10.2.custom/css/ui-lightness/jquery-ui-1.10.2.custom.min.css" />
<script language="javascript" type="text/javascript" src="<?php echo base_url(); ?>jquery/jquery-ui-1.10.2.custom/js/jquery-1.9.1.js"></script>
<script language="javascript" type="text/javascript" src="<?php echo base_url(); ?>jquery/jquery-ui-1.10.2.custom/js/jquery-ui-1.10.2.custom.min.js"></script>

<script type="text/javascript" language="javascript">
  $(function() {
    $( "#tabs" ).tabs();
  });
</script>

<div id="header"><h1>HEADER</h1></div>
    <div id="tabs">
        <ul>
            <li><a href="#">Home</a></li>
            <li><a href="#">Gallery</a></li>
            <li><a href="#">About Me</a></li>
            <li><a href="#">All About Love</a></li>
        </ul>
    </div>
</head>

这是内容的视图(标题):

<body>
<div id="content">
    <?php echo $content; ?>
</div>

 

这是加载标题和内容的控制器:

class Home extends CI_Controller {
public function __construct() {
    parent::__construct();  
    $this->load->model('content_m');
}

public function index() {
    $get_content = $this->content_m->get_content('mscontent');

    foreach($get_content as $temp)
        $data['content'] = $temp->content;

    $this->load->view('header_v');
    $this->load->view('home_v', $data);
}

我的错误在哪里?谢谢:D

修改:

这是我查看页面源时生成的代码:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Johanes Indra</title>
<link rel="stylesheet" href="http://localhost/ci_buku_indra/jquery/jquery-ui-1.10.2.custom/css/ui-lightness/jquery-ui-1.10.2.custom.min.css" />
<script language="javascript" type="text/javascript" src="http://localhost/ci_buku_indra/jquery/jquery-ui-1.10.2.custom/js/jquery-1.9.1.js"></script>
<script language="javascript" type="text/javascript" src="http://localhost/ci_buku_indra/jquery/jquery-ui-1.10.2.custom/js/jquery-ui-1.10.2.custom.min.js"></script>

<script type="text/javascript" language="javascript">
  $(function() {
    $( "#tabs" ).tabs();
  });
</script>

<div id="header"><h1>HEADER</h1></div>
    <div id="tabs">
        <ul>
            <li><a href="#">Home</a></li>
            <li><a href="#">Gallery</a></li>
            <li><a href="#">About Me</a></li>
            <li><a href="#">All About Love</a></li>
        </ul>
    </div>
</head>
<body>
    <div id="content">
        content dari DB </div>
</body>
</html> 

3 个答案:

答案 0 :(得分:1)

指的是jquery ui

同样在你的代码中,你已经在头标记中放置了div id =“header”这是不好的做法 您的视图header_v.php应包含

<!doctype html> 
<html lang="en">
<head>
<meta charset="utf-8" />
<title>jQuery UI Tabs - Default functionality</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<script>
$(function() {
$( "#tabs" ).tabs();
});
</script>
</head>
<body>
<div id="tabs">
 <ul>
<li><a href="#tabs-1">Nunc tincidunt</a></li>
<li><a href="#tabs-2">Proin dolor</a></li>
<li><a href="#tabs-3">Aenean lacinia</a></li>
 </ul>

您的home_v.php或$content应该包含您在html主播中输入的相关div ID href

 <div id="tabs-1">
 <p>Proin elit arcu, rutrum commodo, vehicula tempus, commodo a, risus. Curabitur nec arcu. Donec sollicitudin mi sit amet mauris. Nam elementum quam ullamcorper ante. Etiam aliquet massa et lorem. Mauris dapibus lacus auctor risus. Aenean tempor ullamcorper leo. Vivamus sed magna quis ligula eleifend adipiscing. Duis orci. Aliquam sodales tortor vitae ipsum. Aliquam nulla. Duis aliquam molestie erat. Ut et mauris vel pede varius sollicitudin. Sed ut dolor nec orci tincidunt interdum. Phasellus ipsum. Nunc tristique tempus lectus.</p>
  </div>
  <div id="tabs-2">
  <p>Morbi tincidunt, dui sit amet facilisis feugiat, odio metus gravida ante, ut pharetra massa metus id nunc. Duis scelerisque molestie turpis. Sed fringilla, massa eget luctus malesuada, metus eros molestie lectus, ut tempus eros massa ut dolor. Aenean aliquet fringilla sem. Suspendisse sed ligula in ligula suscipit aliquam. Praesent in eros vestibulum mi adipiscing adipiscing. Morbi facilisis. Curabitur ornare consequat nunc. Aenean vel metus. Ut posuere viverra nulla. Aliquam erat volutpat. Pellentesque convallis. Maecenas feugiat, tellus pellentesque pretium posuere, felis lorem euismod felis, eu ornare leo nisi vel felis. Mauris consectetur tortor et purus.</p>
  </div>
  <div id="tabs-3">
  <p>Mauris eleifend est et turpis. Duis id erat. Suspendisse potenti. Aliquam vulputate, pede vel vehicula accumsan, mi neque rutrum erat, eu congue orci lorem eget lorem. Vestibulum non ante. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Fusce sodales. Quisque eu urna vel enim commodo pellentesque. Praesent eu risus hendrerit ligula tempus pretium. Curabitur lorem enim, pretium nec, feugiat nec, luctus a, lacus.</p>

<p>Duis cursus. Maecenas ligula eros, blandit nec, pharetra at, semper at, magna. Nullam ac lacus. Nulla facilisi. Praesent viverra justo vitae neque. Praesent blandit adipiscing velit. Suspendisse potenti. Donec mattis, pede vel pharetra blandit, magna ligula faucibus eros, id euismod lacus dolor eget odio. Nam scelerisque. Donec non libero sed nulla mattis commodo. Ut sagittis. Donec nisi lectus, feugiat porttitor, tempor ac, tempor vitae, pede. Aenean vehicula velit eu tellus interdum rutrum. Maecenas commodo. Pellentesque nec elit. Fusce in lacus. Vivamus a libero vitae lectus hendrerit hendrerit.     </p>
</div>
</div>

答案 1 :(得分:1)

将div(标题,标签)放在body标签中并关闭所有div。我认为它会奏效。

答案 2 :(得分:0)

您在javascript代码中使用标签,它将返回一个包含多个面板的单个内容区域,每个面板都与列表中的标题相关联。