加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

twitter-bootstrap – 如果从远程加载失败,则加载本地引导程序cs

发布时间:2020-12-17 21:20:31 所属栏目:安全 来源:网络整理
导读:我正在尝试加载本地css远程文件不可用时的js文件. (wifi断开连接) 主要问题是“我不知道如何让css加载正确”. 据我所知,jquery应该放在body的底部以减少页面加载时间. 在浏览器的地址行中,我输入localhost:8000 // example.html(使用静态网页Web浏览器). De
我正在尝试加载本地css&远程文件不可用时的js文件. (wifi断开连接)
主要问题是“我不知道如何让css加载正确”.
据我所知,jquery应该放在body的底部以减少页面加载时间.
在浏览器的地址行中,我输入localhost:8000 // example.html(使用静态网页Web浏览器).

Demo Code

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width,initial-scale=1" />
  <meta name="description" content="Go By Example - Google Go (golang) code examples" />
  <link rel="icon" href="favicon.ico">
  <title>Go by Example - Google Go (golang) code examples</title>
  <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
  <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
</head>
  <body>
    <span class="glyphicon glyphicon-flash"></span>
    ...
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>!window.jQuery && document.write(unescape('%3Cscript src="js/jquery.min.js"%3E%3C/script%3E'))</script>
<script id="bsscript" src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script>$("#bsscript").load("js/bootstrap.min.js")</script>

  </body>
</html>

输出铬的错误信息

GET file://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css net::ERR_FILE_NOT_FOUND local.html:9
GET file://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css net::ERR_FILE_NOT_FOUND local.html:10
GET http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js net::ERR_INTERNET_DISCONNECTED local.html:16
GET file://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js net::ERR_FILE_NOT_FOUND local.html:18

解决方法

bootstrap cdn回调:

<head>
  <!-- Bootstrap CSS CDN -->
  <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
</head>
<body>
  <!-- APP CONTENT -->

  <!-- jQuery CDN -->
  <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
  <!-- jQuery local fallback -->
  <script>window.jQuery || document.write('<script src="/local/jquery.min.js"></script>')</script>
  <!-- Bootstrap JS CDN -->
  <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
  <!-- Bootstrap JS local fallback -->
  <script>if(typeof($.fn.modal) === 'undefined') {document.write('<script src="/local/bootstrap.min.js"></script>')}</script>
  <!-- Bootstrap CSS local fallback -->
  <script>
    $(document).ready(function() {
    var bodyColor = $('body').css('color');
    if(bodyColor != 'rgb(51,51,51)') {
    $("head").prepend('<link rel="stylesheet" href="/local/bootstrap.min.css">');}});
  </script>
</body>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读