jquery - Primefaces 日历,为周末和节假日应用自定义样式

标签 jquery primefaces

我想为 p:calendar 应用周末和节假日的 CSS。我正在尝试调用 beforeShowDay 事件使用 jQuery 并根据条件设置 css。

<script>
    $(document).ready(function(){
       $(".hasDatepicker").datepicker("option", "beforeShowDay", function (date) {
          //If condition true
          return [true,'holidays'];
          //else
          return [true,''];
       });
    });     
</script>

<style>
    .holidays {background-color: wheat;}
</style>

<h:form prependId="false">
      <p:calendar/>
</h:form>

但是该事件没有被解雇。我还缺少什么吗,或者有其他方法吗?

最佳答案

您应该使用beforeShowDay属性

beforeShowDay : Callback to execute before displaying a date, used to customize date display.

Use beforeShowDay javascript callback to customize the look of each date. The function returns an array with two values, first one is flag to indicate if date would be displayed as enabled and second parameter is the optional style class to add to date cell. Following example disabled tuesdays and fridays. (PrimeFaces Userʼs Guide page 50)

<p:calendar value="#{dateBean.date}" beforeShowDay="tuesdaysAndFridaysDisabled" />


function tuesdaysAndFridaysDisabled(date) {
    var day = date.getDay();
    return [(day != 2 && day != 5), '']
}

jQuery 解决方案

如果您想在不修改 primefaces 元素的情况下解决此问题,而是使用 jquery datepicker beforeShowDay 属性,请查看本教程 Primefaces calendar – highlight dates

关于jquery - Primefaces 日历,为周末和节假日应用自定义样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13392947/

相关文章:

primefaces - :ckEditor is not working since version 12. 0.5

java - Primefaces - 未捕获的语法错误 : Unexpected token ILLEGAL

css - 如何在 panelGrid 中对齐 outputLabel 和 selectOneMenu

primefaces - p :button to toggle inplace input

javascript - 检测用户是否单击 Canvas 内的任何圆圈

c# - 回发后,我的 JavaScript 函数在 ASP.NET 中不起作用

jQuery 重新加载 div 的内容(动态渲染)

javascript - CSS 3D 变换只有一半可点击

php - 使用 Ajax 的动态菜单

jsf-2 - Primefaces 日历时区处理固定后端时区