current position:Home>It is normal to directly open HTML locally. Localhost accesses successfully, but CSS, JS, audio and other information are missing

It is normal to directly open HTML locally. Localhost accesses successfully, but CSS, JS, audio and other information are missing

2022-01-27 01:43:39 CSDN Q & A

Open several in the project directly in the local browser html normal .

But by localhost There is a problem with the access . Successful visit , But Web information is missing , Relevant documents in and html The file is in a subfolder under the same path

img

Where is the problem ? How to solve ?




Refer to the answer 1:

The static resource path is incorrect .
open F12, Refresh the page , View the address of the requested resource .




Refer to the answer 2:



Refer to the answer 3:

It's very likely that css,js And the introduction of pictures. You use the absolute address, such as C:/xx/xxx/xx.jpg, You should use relative paths to introduce , In this way, both local and open port numbers can be accessed , But if you use the disk absolute path, you can only double-click the local path to open it html Will load static resources , Therefore, it is suggested that you should css,js And change the picture resources into relative paths




Refer to the answer 4:



Refer to the answer 5:

When referring to the same path subfolder, use the following method directly , Use relative path for reference. Only when you access through port can you obtain resources

"name/2.png"

If it's helpful, please click the button in the upper right corner , thank you

img




Refer to the answer 6:



Refer to the answer 7:

The path used for loading local resource files , You can first use the absolute path configuration to see whether it can be loaded successfully .
Then use the relative path configuration , Check whether the path loaded on the page is correct through the browser debugging page .




Refer to the answer 8:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/01/202201270143371313.html

Random recommended