紫焰璇煌 发表于 2012-8-11 11:18:53

新手求助 图片、js、jq和css显示不了

为什么图片放在views底下就不显示 放在index .php同目录下就可以显示呢???

紫焰璇煌 发表于 2012-8-11 11:33:57

代码:<img src="./images/index.gif" width="200" height="50" />

wx2650 发表于 2012-8-11 13:04:17

图片JSCSS等最好使用绝对路径
<img src="<?php echo $base?>application/views/images/index.gif" width="200" height="50" />

紫焰璇煌 发表于 2012-8-11 13:56:43

wx2650 发表于 2012-8-11 13:04 static/image/common/back.gif
图片JSCSS等最好使用绝对路径

还是不行哦。。

紫焰璇煌 发表于 2012-8-11 15:38:27

每次插入图片都要写base_url()有没有别的方法

gs129090 发表于 2012-8-11 21:37:40

统一放到一个根目录里就可以了,最好用绝对路径

wx2650 发表于 2012-8-12 00:55:11

本帖最后由 wx2650 于 2012-8-12 00:56 编辑


<head>
<title>博客列表</title>
<base href="http://127.0.0.1/Blog/" />
<link rel="stylesheet" type="text/css" href="style.css" />
    <meta http-equiv="Content-Type" content="text/html; charset=GBK" />
    <!-- CuFon: Enables smooth pretty custom font rendering. 100% SEO friendly. To disable, remove this section -->
    <script type="text/javascript" src="js/cufon-yui.js"></script>
    <script type="text/javascript" src="js/arial.js"></script>
    <script type="text/javascript" src="js/cuf_run.js"></script>
</head>


如上
可以看到head中还有很多js和css
上面的JS写的都是相对路径,这个路径是相对于“http://127.0.0.1/Blog/" 来说的

相当于

<link rel="stylesheet" type="text/css" href="http://127.0.0.1/Blog/style.css" />
<script type="text/javascript" src="http://127.0.0.1/Blog/js/arial.js"></script>




因此只要写一个
<base href="<?php echo $base_url ?>" />

其他的图片或者JS就不用写 $base_url了



你还可以新建一个视图来存储“<!DOCTYPE   ”到“</head>”之间的内容

而后,每次新建一个视图时,就只要写

<?php $this->load->view('header');?>
<body>

<!-- web content -->
</body>
</html>

就可以了




ciogao 发表于 2012-8-13 00:29:21

学会使用firebug吧

blcygzs 发表于 2012-8-15 18:24:54

路径问题
页: [1]
查看完整版本: 新手求助 图片、js、jq和css显示不了