Bootstrap datepicker仅适用于firefox

时间:2015-07-06 21:20:54

标签: javascript html5 twitter-bootstrap css3 twitter-bootstrap-3

我一直在尝试在我的网站上调整bootstrap datepicker,但我无法让它工作。我决定使用一个基本的bootstrap设置来尝试让日期选择器工作。从Bootstrap网站复制了基本标记并根据Eonasdan - Bootstrap 3 datetime picker导入了所有相关脚本和css文件后,我得到了以下代码:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Bootstrap 101 Template</title>
    <!-- Bootstrap -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
    <link href="https://raw.githubusercontent.com/Eonasdan/bootstrap-datetimepicker/master/build/css/bootstrap-datetimepicker.min.css" rel="stylesheet">
  </head>
  <body>
    <h2> test</h2>
    <div class="container">
        <div class="row">
            <div class='col-sm-6'>
                <div class="form-group">
                    <div class='input-group date' id='datetimepicker1'>
                        <input type='text' class="form-control" />
                        <span class="input-group-addon">
                            <span class="glyphicon glyphicon-calendar"></span>
                        </span>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
    <script src="https://raw.githubusercontent.com/moment/moment/develop/moment.js"></script>
    <script src="https://raw.githubusercontent.com/Eonasdan/bootstrap-datetimepicker/master/build/js/bootstrap-datetimepicker.min.js"></script>
    <script type="text/javascript">
        $(function () {
            $('#datetimepicker1').datetimepicker();
        });
    </script>
  </body>
</html>

我使用Datepicker with jQuery UI and Bootstrap来形成上述代码。 我的问题是这只适用于Firefox。如何让它在所有浏览器上运行?

1 个答案:

答案 0 :(得分:1)

您无法直接链接到https://raw.gitbuhusercontent.com/,因为GitHub使用的X-Content-Type-Options: nosniff不允许浏览器猜测您正在使用的内容的类型。因此,如果您链​​接到https://raw.gitbuhusercontent.com/,则浏览器将其视为'text/plain',并且无法以javascript的形式执行。

只需在您的javascript链接中将https://raw.gitbuhusercontent.com/替换为https://cdn.rawgit.com/

以示例:

<script src="https://raw.githubusercontent.com/moment/moment/develop/moment.js"></script>

<script src="https://cdn.rawgit.com/moment/moment/develop/moment.js"></script>

相关问题