Transferred from: http://blog.csdn.net/luohuidong01/article/details/74938652
The difference between JS and CSS relative path reference is that their reference point is different, here is an example to illustrate.
The file directory is as follows
|--css| | __ Mystyle.css|--script| | __ myscript.js|--images| | __ myimage.jpg|--index.html
The HTML code is as follows
<! DOCTYPE html>
We use CSS to myimage.jpg as a background image of DIV elements
div { width:300px; height:300px; Background:url ('.. /images/check.png ');}
We then use JS to change the IMG element to show myimage.jpg
Window.onload = Initpage;function Initpage () { var IMGs = document.getelementsbytagname ("img"); IMGS[0].SRC = "Images/check.png";}
Please take a look at the relative reference path in CSS and JS.
The relative reference path in CSS is written as a reference point for the CSS file itself.
The relative reference path of JS is a reference point for the location of the HTML file using this external JS file.
Differences between JavaScript and CSS relative path references