I'm using datepicker for bootstrap from this site http://www.eyecon.ro/bootstrap-datepicker
I want to alert the date value when it clicked on date. I have these codes:
HTML:
<div id="datepicker" class="input-append date pull-right" data-date-format="dd-mm-yyyy" data-date="12-02-2012">
<input class="span2" type="text" value="12-02-2012" size="16" style=" width:95px;"></input>
<span class="add-on"><i class="icon-th"></i></span>
</div>
JQuery:
$('#datepicker').datepicker();
$('#datepicker').datepicker().on('changeDate', function(){
alert($(this).data('date'));
});
It's works, but when i click month or year, it's also alerting. How do i fix this? Thanks
Try onselect
event of daatepicker
$('#datepicker').datepicker({
onSelect: function(dateText, inst) {
alert(dateText)
}
})
Called when the datepicker is selected. The function receives the selected date as text and the datepicker instance as parameters. this refers to the associated input field.
OR
$('#datepicker').datepicker().on('changeDate', function(ev){
alert(ev.date);
console.log(ev);
});
EDIT: parse date from Wed Sep 11 2013 00:00:00 GMT+0700 (SE Asia Standard Time) to 11-9-2013
$('#datepicker').datepicker().on('changeDate', function(ev){
console.log(ev);
var d =new Date(Date.parse(ev.date));
dateString =(d.getDate()+1)+"-"+(d.getMonth()+1)+"-"+ d.getFullYear();
alert(dateString)
console.log(dateString)
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.