Home > Web Front-end > JS Tutorial > Detailed explanation about the error in the path of laydate.js loading laydate.css

Detailed explanation about the error in the path of laydate.js loading laydate.css

小云云
Release: 2017-12-27 14:01:13
Original
4319 people have browsed it

laydate.js is a date control and time plug-in belonging to the Javascript series. laydate.js is compatible with mainstream browsers including IE6. After laydate.js was greatly rewritten by Xianxin, it became more and more powerful and more flexible to use, but something went wrong in a project based on angular+ocLazyLoad. I believe that the date and time selection plug-in laydate.js is familiar to everyone. This article mainly introduces to you the relevant information on how to solve the problem of the path error of laydate.js loading laydate.css. The article introduces it in detail through the example code, which is very useful for everyone. It has certain reference and learning value when studying or working. Friends who need it can take a look below.

Discover the problem

laydate.js was introduced through ocLazyLoad asynchronous loading. As a result, the laydate.css file could not be loaded. I looked at the path error, so I opened the code and found that it was written like this. :

getPath:function(){
 var e=document.scripts,
 t=e[e.length-1],
 n=t.src;
 if(!t.getAttribute("merge"))
 return n.substring(0,n.lastIndexOf("/")+1)
}()
Copy after login

It is necessary to first obtain the path to laydate.js, and then add the section of laydate.css to finally splice it into one full path.

The author uses the idea of ​​​​obtaining the path of laydate.js: Since the js code for determining the path is generally placed directly in the js file instead of the function, it will be executed immediately when the js file is loaded. statement in it, and the number of js files obtained when executing this statement is exactly e.length-1. Because the js files behind the page have not been loaded yet, the number of js files obtained there is not all the js files on the page. Number of. In this way, there is no need to traverse the path to obtain the file, and the file name is not required for file judgment, making the judgment more accurate (e.length-1 is always the file itself).

However, this method has flaws. It is no problem to introduce it directly with the script tag in the html page. If you pass document.write("

Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template