js控制重新加载css和js以及获取本地目录

转:https://blog.csdn.net/yhq1913/article/details/51991231

1 重新加载js的方法

  1. var head = $("head").remove("script[role='reload']");  
  2.             $(" + "pt>" + " + "ipt>").attr({ role: 'reload', src: getRootPath()+"/js/video.js", type: 'text/javascript' }).appendTo(head);

2 重新加载css的方法

  1. var link = document.createElement("link");  
  2. link.rel = "stylesheet";  
  3. link.type = "text/css";  
  4. link.href = getRootPath()+"/css/video.css";  
  5. document.getElementsByTagName("head")[0].appendChild(link);
function getRootPath() {
//获得根目录

var strFullPath = window.document.location.href;

var strPath = window.document.location.pathname;

var pos = strFullPath.indexOf(strPath);

var prePath = strFullPath.substring(0, pos);

var postPath = strPath.substring(0, strPath.substr(1).indexOf('/') + 1);

return (prePath + postPath);
}


你可能感兴趣的:(js控制重新加载css和js以及获取本地目录)