这个要点有一个代码片段,我发现它对于检测是否需要加载 CSS 回退特别有用。
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/css/bootstrap-combined.min.css" />
<script type="text/javascript">
function cssLoaded(href) {
var cssFound = false;
for (var i = 0; i < document.styleSheets.length; i++) {
var sheet = document.styleSheets[i];
if (sheet['href'].indexOf(href) >= 0 && sheet['cssRules'].length > 0) {
cssFound = true;
}
};
return cssFound;
}
if (!cssLoaded('bootstrap-combined.min.css')) {
local_bootstrap = document.createElement('link');
local_bootstrap.setAttribute("rel", "stylesheet");
local_bootstrap.setAttribute("type", "text/css");
local_bootstrap.setAttribute("href", "/Content/Styles/bootstrap-combined.min.css");
document.getElementsByTagName("head")[0].appendChild(local_bootstrap);
}
</script>
只需/Content/Styles/bootstrap-combined.min.css
用正确的路径替换到本地 css 就可以了