欢迎大家访问我的BLOG,我会多多的出原创文章,希望大家支持我,为我祈祷,让我实现我的三个梦想!再30岁能成为一个名优秀的软件架构师!

关于javascript和css的宿主环境以及资源引用相对路径等问题实践总结!

关于javascript和css的宿主环境以及资源引用相对路径等问题实践总结!

1.javascript引用资源(比如图片)相对路径是以宿主环境(所被引用的网页比如user.html)所处位置为基准

2.css引用资源(比如图片)相对路径是以.css文件所处位置为基准!

已经实践证明过!

--2009aicheaizi
------images
---------index_02.jpg
------test.htm

--css
------css
----------test.css

--js
------js
----------test.js

引用代码如下:
test.css
#imgtest
{
 background-image:url(。。/。。/2009aicheaizi/images/index_02.jpg);//把.换成。以防cnblogs转换
 width:500px;
 height:50px;
 border:solid 1px red;
}

test.js

function writeimg()
{
  document.write("<img src='images/index_02.jpg' />");
}

 test.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>无标题页</title>
 <script type="text/javascript" src="../js/js/test.js"></script>
  <link href="../css/css/test.css" rel="stylesheet" type="text/css" />
</head>
<body>
<script type="text/javascript">
writeimg();
</script>
<div id="imgtest"></div>
</body>
</html>
实践是检验真理的唯一途径.

posted on 2009-07-29 11:46  程序缘  阅读(543)  评论(0编辑  收藏  举报

导航