0

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

在此处输入图像描述

这是我的标题的观点:

<!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> 
4

3 回答 3

1

将您的 divs(header,tabs) 放在 body 标记中并关闭所有 div。我认为它会起作用。

于 2013-04-08T12:53:52.250 回答
1

参考jquery ui

同样在您的代码中,您已将divwith id="header" 放在 head 标记内,这是不好的做法您的视图 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 idhref

 <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>
于 2013-04-08T12:46:58.307 回答
0

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

于 2013-04-08T12:31:24.460 回答