获取 bootstrap-datepicker 中的点击日期
我尝试获取在引导日期选择器中单击的日期。这是到目前为止的代码,我检索所选的日期而不是单击的日期。我需要更改什么才能获取点击日期?
<script type="text/javascript">
var disableDates = ["1-3-2022", "3-3-2022"];
$('#calendar').datepicker({
format: 'yyyy/mm/dd',
language: "sv",
beforeShowDay: function(date){
dmy = date.getDate() + "-" + (date.getMonth() + 1) + "-" + date.getFullYear();
if(disableDates.indexOf(dmy) != -1){
return false;
}
else{
return true;
}
},
dayClick: function (date, jsEvent, view) {
alert("Day Clicked");
},
eventClick: function (event) {
alert('event');
}
});
$("#calendar .datepicker-days").on('click', 'td.day', function () {
let selecteddate = $("#calendar").data('datepicker').getFormattedDate('yyyy-mm-dd');
alert('day clicked ' + selecteddate);
});
</script>
I try to get the date clicked in the bootstrap-datepicker. This is the code so far, I retrieve the date that is selected and not the date that is clicked. What do I need to change to get the clicked date?
<script type="text/javascript">
var disableDates = ["1-3-2022", "3-3-2022"];
$('#calendar').datepicker({
format: 'yyyy/mm/dd',
language: "sv",
beforeShowDay: function(date){
dmy = date.getDate() + "-" + (date.getMonth() + 1) + "-" + date.getFullYear();
if(disableDates.indexOf(dmy) != -1){
return false;
}
else{
return true;
}
},
dayClick: function (date, jsEvent, view) {
alert("Day Clicked");
},
eventClick: function (event) {
alert('event');
}
});
$("#calendar .datepicker-days").on('click', 'td.day', function () {
let selecteddate = $("#calendar").data('datepicker').getFormattedDate('yyyy-mm-dd');
alert('day clicked ' + selecteddate);
});
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论