请帮助我,我已经搜索了如何获得周数和范围。我找到了以下来源.. stackoverflow.com/questions/30230615/fetch-week-number-and-week-start-end-date-using-bootstrap-datepicker和 Bootstrap datepicker: Select entire week and put week interval in input field
我尝试使用代码,以便我可以选择整周并在输入字段中输入周间隔并显示周数。但它不适合我,有人可以帮我解决我的问题吗?请帮我。提前谢谢。
以下是我使用的脚本标记。
<!--jquery-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<!--bootstrap-->
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<!--datepicker-->
<link href="http://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.3.0/css/datepicker.css" rel="stylesheet" type="text/css" />
<script src="http://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.3.0/js/bootstrap-datepicker.js"></script>
<!--moment-->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.11.1/moment.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/momentjs/2.10.6/moment.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment-with-locales.js"></script>
这是我的HTML代码。
<div class='input-group date' id='datepicker2'>
<input type='text' id='datepicker' class="form-control" />
<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
</div>
<div id="output"></div>
这是我的javascript ..
$('#datepicker2').on('dp.change', function (e) {
var kk = $('#datepicker2').val();
var value = $('#datepicker2').val();
var firstDate = moment(value, "MM-DD-YYYY").day(0).format("MM-DD-YYYY");
var lastDate = moment(value, "MM-DD-YYYY").day(6).format("MM-DD-YYYY");
$('#datepicker2').val(firstDate + " - " + lastDate);
$("#output").html(
"Week Number: " + moment(kk, "DD/MM/YYYY").week() + " of " +
moment(kk, "DD/MM/YYYY").weeksInYear()
);
});