在Bootstrap Datepicker中将当前日期设置为默认日期,并使其与语言环境配合使用

时间:2018-09-04 11:38:12

标签: html twitter-bootstrap datetimepicker

这是我的HTML代码:

<html>
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

    <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" />
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/css/bootstrap-datetimepicker.min.css" />
    <link rel="stylesheet" href="style.css">
    <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://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.min.js"></script>                       
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/locale/pl.js"></script>

</head>
<body>
    <div class="col-xs-5">
    <label for="mail">Mail:</label>
    <input type="text" class="form-control" id="mail">
    </div>
    <div class="col-xs-5">
    <label for="date">Data:</label>
    <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 class="col-xs-5">
    <label for="adress">Adres:</label>
    <input type='text' class="form-control" id="adress">
    </div> 
    <div class="col-xs-5">
    <label for="fliers">Ulotki:</label>
    <input type='text' class="form-control" id="fliers">
    </div> 
    <div id="button">
        <div id="button_container">
            <button type="button" class="btn btn-success">Pobierz dane</button>
        </div>
    </div>

    <script type="text/javascript">

        $(function () {
            $('#datetimepicker1').datetimepicker({locale:'pl'});
        });
    </script>


</body>

Datetimepicker无法在我的语言环境中正常工作,因为我将当前日期定为3月9日,而不是9月3日,所以显然月份和日期是混杂的。我尝试了以下功能来设置正确的日期:

$("#datetimepicker1").datetimepicker().datetimepicker("setDate", new Date());

当我使用它时,日历语言会恢复为英文。

0 个答案:

没有答案