Jquery Datepicker beforeShowDay 不显示工具提示并且不分配类作为回报

发布于 2025-01-10 19:38:31 字数 2485 浏览 0 评论 0原文

我试图在嵌入的日期选择器(而不是在输入字段中)中为某些日子的背景着色,并在悬停在这些相同颜色的日子上时触发工具提示,但没有执行任何操作。我检查了控制台,工具提示消息在那里,但不在日历中,而且背景颜色也没有应用。我尝试仅使用“return {Classes:“activeClass”}”应用背景颜色而不使用工具提示,它可以工作,但不是我需要的。非常感谢任何帮助。

工具提示的日期数组和文本是使用 PHP 生成的。

这是我的代码:

    <style>
        .activeClass{
            color: #fff;
            background-color: #339966; 
        }        
    </style>

    <script>
        var active_dates = ["4/10/2022", "5/1/2022", "5/29/2022", "6/26/2022", "7/10/2022", "7/24/2022", "8/7/2022", "8/21/2022", "9/11/2022", "9/25/2022", "10/9/2022", "10/16/2022", "11/6/2022", "12/25/2022", ]; 
        var tooltips = [];
        tooltips[new Date('4/10/2022')] = 'DBL: 1689.00/ TWN: 1689.00'; tooltips[new Date('5/1/2022')] = 'DBL: 1729.00/ TWN: 1729.00'; tooltips[new Date('5/29/2022')] = 'DBL: 1799.00/ TWN: 1799.00'; tooltips[new Date('6/26/2022')] = 'DBL: 1799.00/ TWN: 1799.00'; tooltips[new Date('7/10/2022')] = 'DBL: 1799.00/ TWN: 1799.00'; tooltips[new Date('7/24/2022')] = 'DBL: 1799.00/ TWN: 1799.00'; tooltips[new Date('8/7/2022')] = 'DBL: 1799.00/ TWN: 1799.00'; tooltips[new Date('8/21/2022')] = 'DBL: 1799.00/ TWN: 1799.00'; tooltips[new Date('9/11/2022')] = 'DBL: 1729.00/ TWN: 1729.00'; tooltips[new Date('9/25/2022')] = 'DBL: 1729.00/ TWN: 1729.00'; tooltips[new Date('10/9/2022')] = 'DBL: 1689.00/ TWN: 1689.00'; tooltips[new Date('10/16/2022')] = 'DBL: 1689.00/ TWN: 1689.00'; tooltips[new Date('11/6/2022')] = 'DBL: 1689.00/ TWN: 1689.00'; tooltips[new Date('12/25/2022')] = 'DBL: 1689.00/ TWN: 1689.00';  
        var date = new Date();
        date.setDate(date.getDate()+1);
        $('#date_pick').datepicker({     
            showOtherMonths: true,
            selectOtherMonths: true,
            startDate: date,
            format: 'mm/dd/yyyy',
            todayHighlight: false,
            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 formattedDate = curr_month + "/" + curr_date + "/" + curr_year
                if ($.inArray(formattedDate, active_dates) != -1){

                    var tooltip = tooltips[date]; 
                    return [true, "activeClass",tooltip],
                    console.log(tooltip);

                }
                return;
            }
        });
    </script>

I'm trying to color the background of certain days in an embedded datepicker (not in an input field) and fire a tooltip on hover on those same colored days but is not doing anything. I checked in the console and the tooltips messages are there but not in the calendar, and also the background color is not been applied. I tried just applying a background color without the tooltip using only 'return {Classes: "activeClass"}' and it works but is not what I need. Any help is very much appreciated.

The date arrays and text for the tooltips are been generating with PHP.

Here is my code:

    <style>
        .activeClass{
            color: #fff;
            background-color: #339966; 
        }        
    </style>

    <script>
        var active_dates = ["4/10/2022", "5/1/2022", "5/29/2022", "6/26/2022", "7/10/2022", "7/24/2022", "8/7/2022", "8/21/2022", "9/11/2022", "9/25/2022", "10/9/2022", "10/16/2022", "11/6/2022", "12/25/2022", ]; 
        var tooltips = [];
        tooltips[new Date('4/10/2022')] = 'DBL: 1689.00/ TWN: 1689.00'; tooltips[new Date('5/1/2022')] = 'DBL: 1729.00/ TWN: 1729.00'; tooltips[new Date('5/29/2022')] = 'DBL: 1799.00/ TWN: 1799.00'; tooltips[new Date('6/26/2022')] = 'DBL: 1799.00/ TWN: 1799.00'; tooltips[new Date('7/10/2022')] = 'DBL: 1799.00/ TWN: 1799.00'; tooltips[new Date('7/24/2022')] = 'DBL: 1799.00/ TWN: 1799.00'; tooltips[new Date('8/7/2022')] = 'DBL: 1799.00/ TWN: 1799.00'; tooltips[new Date('8/21/2022')] = 'DBL: 1799.00/ TWN: 1799.00'; tooltips[new Date('9/11/2022')] = 'DBL: 1729.00/ TWN: 1729.00'; tooltips[new Date('9/25/2022')] = 'DBL: 1729.00/ TWN: 1729.00'; tooltips[new Date('10/9/2022')] = 'DBL: 1689.00/ TWN: 1689.00'; tooltips[new Date('10/16/2022')] = 'DBL: 1689.00/ TWN: 1689.00'; tooltips[new Date('11/6/2022')] = 'DBL: 1689.00/ TWN: 1689.00'; tooltips[new Date('12/25/2022')] = 'DBL: 1689.00/ TWN: 1689.00';  
        var date = new Date();
        date.setDate(date.getDate()+1);
        $('#date_pick').datepicker({     
            showOtherMonths: true,
            selectOtherMonths: true,
            startDate: date,
            format: 'mm/dd/yyyy',
            todayHighlight: false,
            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 formattedDate = curr_month + "/" + curr_date + "/" + curr_year
                if ($.inArray(formattedDate, active_dates) != -1){

                    var tooltip = tooltips[date]; 
                    return [true, "activeClass",tooltip],
                    console.log(tooltip);

                }
                return;
            }
        });
    </script>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

三月梨花 2025-01-17 19:38:31

return [true, "activeClass",tooltip] 行末尾有一个 ,,而不是 ;。首先修复它,因为它可能会导致问题......

You have a , at the end of the return [true, "activeClass",tooltip] line instead of a ;. First fix that as it may cause the issue...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文