gpt4 book ai didi

javascript - 如何在日期选择器中添加自定义模板。?

转载 作者:行者123 更新时间:2023-11-30 20:55:26 25 4
gpt4 key购买 nike

我正在使用 Bootstrap 日期选择器 http://bootstrap-datepicker.readthedocs.io/en/latest/对于我的项目,我想知道如何为特定日期添加自定义图标。我的要求是为特定日期的事件添加图标。

enter image description here

图像显示了我需要的输出(第 15 天的图标)。期待解决方案。提前致谢。 :)

我使用的代码。

 $('.datepicker').datepicker({
keyboardNavigation: false,
forceParse: false,
templates:{
leftArrow: '<i class="material-icons icon-30">keyboard_arrow_left</i>',
rightArrow: '<i class="material-icons icon-30">keyboard_arrow_right</i>',
},
beforeShowDay: function(date){
var d = date;
var curr_date = d.getDate();
var curr_month = d.getMonth() + 1; //Months are zero based
var curr_year = d.getFullYear();
var formate_date = curr_date + "/" + curr_month + "/" + curr_year
if ($.inArray(formate_date, specific_date) != -1){
return {
classes: 'addIcon' // Here i want to add an icon for a partiicular date.
};
}
}

});

This is what I actually want. :)

最佳答案

您可以使用 beforeShowDay 事件在特定日期添加类(class)

var specific_date = ["15/12/2017","16/12/2017"];
beforeShowDay: function(date){
var d = date;
var curr_date = d.getDate();
var curr_month = d.getMonth() + 1; //Months are zero based
var curr_year = d.getFullYear();
var formate_date = curr_date + "/" + curr_month + "/" + curr_year
if ($.inArray(formate_date, specific_date) != -1){
return {
classes: 'addIcon'
};
}
return;
}

then you can add anything using css

.addIcon::after{
content: "\25CF";
font-size:10px;
color: blue;
position: absolute;
bottom: -6px;
left: 12px;
}
.day{
position: relative;
}

关于javascript - 如何在日期选择器中添加自定义模板。?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47713041/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com