0

My site layout (for this example):

localhost/mydomain/
-localhost/mydomain/pics
-localhost/mydomain/somepages/arandompage.php

I want to access picture from here:

localhost/mydomain/index.php

I did this:

<img id='4' src='pics/somepic.1.jpg'>

The mouseover snippet:

{ $('#'+someId).attr('src', 'pics/somepic.'+num+'.jpg');

This is working. But when I wanted to access it from here it doesn’t work. But when you go localhost/mydomain/somepages/arandompage.php it obviously doesn't work, no longer relative.

<img id='4' src='../pics/somepic.1.jpg'>

Ok here obviously that'll fix the display image. It is not working in JavaScript.

{ $('#'+videoId).attr('src', '../pics/somepic.'+num+'.jpg'); /

I don't know what to do here, but yes all I need is the JavaScript to just look back 1 folder to get that img src. That's all. If you answer please insert what should be here in:

`{ $('#'+videoId).attr('src', ====> 'pics/somepic.'+num+'.jpg');` 

So that it goes to the parent directory.

P.S. I tried absolute paths but to no avail either.

4

1 回答 1

0

关键是要记住浏览器的层次结构视图是什么:

  1. 假设localhost/mydomain是您网站的根目录,则:

    ...类似的页面localhost/mydomain/somepage.php

    • 将出现在例如http://example.com/somepage.php浏览器的 POV

    • 并且可以使用pics/somepic.jpg/pics/somepic.jpg用于图片。

    ...类似的页面localhost/mydomain/somepages/somepage.php

    • 将出现在例如http://example.com/somepages/somepage.php浏览器的 POV

    • 并且可以使用../pics/somepic.jpg/pics/somepic.jpg用于图片。

  2. 假设localhost是您网站的根目录,则:

    ...像这样的页面localhost/mydomain/somepage.php

    • 将出现在例如,http://example.com/mydomain/somepage.php从浏览器的 POV

    • 并且可以使用pics/somepic.jpg/mydomain/pics/somepic.jpg用于图片。

    ...像这样的页面localhost/mydomain/somepages/somepage.php

    • 将出现在例如,http://example.com/mydomain/somepages/somepage.php从浏览器的 POV

    • 并且可以使用../../pics/somepic.jpg/mydomain/pics/somepic.jpg用于图片。

于 2013-07-01T10:18:56.320 回答