开发者

the releative path in javascript

开发者 https://www.devze.com 2023-02-11 06:10 出处:网络
I meet some problem when locate the resources such as css js img in the page. For example,I want to use a javascript lib:dtree,it contain some built-in images and css.

I meet some problem when locate the resources such as css js img in the page.

For example,I want to use a javascript lib:dtree,it contain some built-in images and css.

This is its structure:

img
dtree.css
dtree.js
example.html

The exmaple.html is a live demo to show how to use dtree. It use the dtree.js as:

<script type="text/javascript" src="dtree.js"></script>

Now I create a new folder,and copy the example.html here,and modify the src of the js:

<script type="text/javascript" src="../dtree.js"></script>

Now,this is the new structure:

img
dtree.css
dtree.js
example.html
chd
--example.html

When I browser the chd/example.html,some required imgs are missing.

And in the dtree.js,there are some codes like:

this.icon = {
  root:'img/base.gif',
  ....
}

So I think the img here are not based on the dtree.js but the current page which call the js.

If so,I think I am fxxked.

I have to put all my pages to the same directory with the img(it contains the required imgs by dtree.js) if I 开发者_Python百科want to use the dtree.js?

And solutions?


you need to adjust image root path by adding slash before img like:

this.icon = {
  root:'/img/base.gif',
  ....
}
0

精彩评论

暂无评论...
验证码 换一张
取 消