The example in this article describes the simple implementation of web page skinning effect using js+css. Share it with everyone for your reference, the details are as follows:
Three sets of appearances are made here, using css files with the same name in different folders. So how to implement js replacement loading?
The 3 buttons are as follows:
<a id="skin1" href="javascript:void(0)" class="easyui-linkbutton" onclick="changeCss('default')">蓝色皮肤</a><br/><br/> <a id="skin2" href="javascript:void(0)" class="easyui-linkbutton" onclick="changeCss('gray')">灰色皮肤</a><br/><br/> <a id="skin3" href="javascript:void(0)" class="easyui-linkbutton" onclick="changeCss('unite')">自定义皮肤</a>
js code:
// 更换主题 function changeCss(cssName) { if (document.getElementsByTagName_r("link").length > 0) { for(var i = 0 ; i < document.getElementsByTagName_r("link").length; i++){ var ctrlLink = document.getElementsByTagName_r("link")[i]; var cssOld = ctrlLink.getAttribute("href"); var cssNew = cssOld.replace("default", cssName); cssNew = cssNew.replace("gray", cssName); cssNew = cssNew.replace("unite", cssName); ctrlLink.setAttribute("href", cssNew); } } }
Realization effect:
I hope this article will be helpful to everyone in JavaScript programming.