这个代码段能让使用easyUI的网页更换主题,包括本网页中的iframe也会跟着换主题 function changetheme(str){ $("body").fadeOut('fast',function(){ var links = document.getElementsByTagName("link"); var link = null; for
function changetheme(str){ $("body").fadeOut('fast',function(){ var links = document.getElementsByTagName("link"); var link = null; for (var i = 0; i < links.length; i++) { if(links[i].href.substr(-10) == "easyui.css"){ link = links[i]; } } link.href="${pageContext.request.contextPath}/easyui/themes/"+str+"/easyui.css"; //对iframe进行更换主题 var iframes = document.getElementsByTagName('iframe'); for (var i = 0; i < iframes.length; i++) { links = iframes[i].contentDocument.getElementsByTagName('link'); for (var j = 0; j < links.length; j++) { if(links[j].href.substr(-10) == "easyui.css"){ link = links[j]; } } link.href="${pageContext.request.contextPath}/easyui/themes/"+str+"/easyui.css"; } //删除变量降低内存占用 i = null; j = null; links = null; link = null; }); $("body").fadeIn(); }