更新时间:2023-11-26 21:26:58
您需要有条件地从浏览器中添加或删除样式:
You'd need to conditionally add or remove the style from the browser:
添加
loadIfNot(url,cssId){
if (!document.getElementById(cssId)){
var head = document.getElementsByTagName('head')[0];
var link = document.createElement('link');
link.id = cssId;
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = url;
link.media = 'all';
head.appendChild(link);
}else{
document.getElementById(cssId).disabled = false;///i fit's already there, enable it
}
}
并删除
disable(cssId){
document.getElementById(cssId).disabled = true
}
Disable
和Enable
是因为浏览器倾向于缓存您的样式,并且为了使它们启用或禁用,您需要更改该属性
Disable
and Enable
is because browser tends to cache your styles, and in order to make them enable or disable, you'd change that attribute