如何在bootstrap daterange picker

时间:2015-07-25 05:19:59

标签: javascript twitter-bootstrap date

请在下面找到我的计划,

如何在div中显示今天的日期...如下面的示例..默认情况下它显示今天的日期,但显示上个月到今天的日期...如果我点击今天下拉仍然显示之前的日期一个月到今天的日期。在页面上加载自身如何显示到日期为今天的日期

<html>
    <head>
        <title></title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Include Required Prerequisites -->
<script type="text/javascript" src="//cdn.jsdelivr.net/jquery/1/jquery.min.js"></script>
<script type="text/javascript" src="//cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
<link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/bootstrap/latest/css/bootstrap.css" />

<!-- Include Date Range Picker -->
<script type="text/javascript" src="//cdn.jsdelivr.net/bootstrap.daterangepicker/2/daterangepicker.js"></script>
<link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/bootstrap.daterangepicker/2/daterangepicker.css" />        

<script type="text/javascript">
$(function() {

    function cb(start, end) {
        $('#reportrange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
        //alert($('#reportrange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY')));
    }
    cb(moment().subtract(29, 'days'), moment());

    $('#reportrange').daterangepicker({
        ranges: {
           'Today': [moment(), moment()],
           'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
           'Last 7 Days': [moment().subtract(6, 'days'), moment()],
           'Last 30 Days': [moment().subtract(29, 'days'), moment()],
           'This Month': [moment().startOf('month'), moment().endOf('month')],
           'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
        }
    }, cb);

});
</script>        

    </head>
    <body>
        <div id="reportrange" class="pull-left" style="background: #fff; cursor: pointer; padding: 5px 10px; border: 1px solid #ccc; width: 20%">
            <i class="glyphicon glyphicon-calendar fa fa-calendar"></i>&nbsp;
            <span></span> <b class="caret"></b>


        </div>
    </body>
</html>

1 个答案:

答案 0 :(得分:0)

我刚刚在您的代码中添加了以下代码,我们在点击按钮时调用if (/*file logger and approx worker*/) { FileLogger log(); ApproximateWorker worker(); Runner runner = Runner(log, worker); } else if (/*file logger and complete worker*/) { FileLogger log(); CompleteWorker worker(); Runner runner = Runner(log, worker); } else if (/*socket logger and approx worker*/) { SocketLogger log(); ApproximateWorker worker(); Runner runner = Runner(log, worker); } else { SocketLogger log(); CompleteWorker worker(); Runner runner = Runner(log, worker); } ,尝试此代码

'getDate()'

编辑:如果您想将开始日期和结束日期存储在不同的变量中,请使用拆分功能

<input type="button" id="GetCalenderDate" value="Get Selected date" onclick="return getDate(); " />

<script>
    function getDate() {
        alert($('#reportrange span')[0].innerHTML); //Using Jquery selector
        alert(document.getElementsByTagName('span')[0].innerHTML); // using Javascript getElementsByTagName()
    }
</script>