There were three ways to consider:
1. Directly write the path in the JS file, but if the reference page path level changes can not.
2. Write a class, put the CSS file in the subject package or create a separate CSS file for the date control. However, the other elements in the control do not use the needs of class, the separate creation of the corresponding CSS document seems to make a fuss.
3. After the above two methods are excluded, it is natural to adopt the method of dynamically loading the picture path.
The key code is as follows:
Copy Code code as follows:
Create a global variable save path
var imgrooturl = "";
Get the directory where the picture path is located
var strpath=window.document.location.pathname; Get the directory part after the host address
var thisurlcount = strpath.split ('/');
var hierarchyoffolders = thisurlcount.length-2;//Get directory hierarchy
for (iroot=0;iroot{
Imgrooturl + = ". /";
}
Imgrooturl + = "images/"; This images can actually be set as a parameter, because all items picture folders are named fixed, so there is no set parameter, but still save extensibility.
When you add a diagram, the control effect is pretty beautiful:
By the way, attach all window.document.location its subordinates:
Document.location.hash//#号后的部分 VS Window.location.hash
Document.location.host//Domain name + port number
Document.location.hostname//Domain
Document.location.href//Full URL
Document.location.pathname//directory section (application)
Document.location.port//Port number
Document.location.protocol//Network Protocol (http:)
Document.location.search//number of parts after