如何将选定的日期月份和年份打印到不同的div标签中

时间:2016-04-25 13:47:58

标签: javascript calendar bootstrap-datepicker

它是一个bootstrap datepicker.js文件我希望从该datepicker中获取日期的月份和日期,并在不同的div标签中打印这些选定的值

$('.from_date').datepicker({
    weekStart: 1,
    startDate: '01/01/2012',
    endDate: FromEndDate, 
    autoclose: true
}).on('changeDate', function(selected){
    startDate = new Date(selected.date.valueOf());
    startDate.setDate(startDate.getDate(newDate(selected.date.valueOf())));
    $('.to_date').datepicker('setStartDate', startDate);
}); 

`

2 个答案:

答案 0 :(得分:0)



$('.from_date').datepicker({
    weekStart: 1,
    startDate: '01/01/2012',
    endDate: '01/10/2012', 
    autoclose: true
}).on('changeDate', function(selected){
    $('.to_date').html(selected.format());
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.0/js/bootstrap-datepicker.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.0/css/bootstrap-datepicker.min.css" rel="stylesheet"/>

<div class="from_date"></div>
<div class="to_date"></div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

我们走了:

var from_date = $(".from_date").val();
var to_date =$(".to_date").val();

//here we are create an example object input:
<input type="text" id="myInputFrom"/>
<input type="text" id="myInputTo"/>

$("#myInputFrom").val(from_date);
$("#myInputTo").val(to_date);

希望它有所帮助;)