【问题标题】:jQuery: Adding Style to selected Day in DatepickerjQuery:在 Datepicker 中为选定的日期添加样式
【发布时间】:2013-05-07 08:50:02
【问题描述】:

我尝试操作 jquery 的日期选择器,因为我想要多选。 现在我想更改所选日期的样式,例如将文本设为绿色。 我不知道如何改变风格。有没有可能?

感谢您的帮助!

这是我的代码:

$(".testpicker").datepicker({

    numberOfMonths: 2,
    showButtonPanel: false,
    onSelect: function(test,object){
        console.log(object.id);

        //#####My first tries######//:
        $("#"+object.id).css('color','green');
        $(this).css('background-color','white');
        //###########//

        if(~$.inArray(test,dates))
        {
            console.log(test)
        }
        else
        {
            dates.push(test);
        }
        console.log(dates);
        console.log(object);
        //prevents closing
        $(this).data('datepicker').inline = true;
    },
    onClose: function() {
        $(this).data('datepicker').inline = false;
    }
});

【问题讨论】:

    标签: jquery jquery-ui-datepicker onselect


    【解决方案1】:

    要更改日期选择器中所选日期的颜色,请在您的 jsp 页面上使用以下 css:

    #ui-datepicker-div .ui-state-highlight {
       background:red;
    }
    

    【讨论】:

      【解决方案2】:

      我认为您需要打开检查器(萤火虫)并查看分配给选定单元格的类(选定日期)。

      例如,今天的这一天被赋予类.ui-state-highlight

      你选择的日期是.ui-state-active

      【讨论】:

      • 没错,但是如何在选定的日期访问?如果是这样的元素“$("#"+object.id).css('color','green');"没问题,但是日期在表格中,看起来像这样: 14
      • 再次,如果您检查 datepicker html,您会发现每个单元格都只是 ,其中包含 。尝试把你的点击事件放在那个
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-17
      • 2010-10-29
      • 1970-01-01
      • 1970-01-01
      • 2014-07-25
      • 1970-01-01
      相关资源
      最近更新 更多