禁用 p:calendar 上的特定日期

编程入门 行业动态 更新时间:2024-10-10 00:29:57
本文介绍了禁用 p:calendar 上的特定日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

是否可以在 PrimeFaces 3.5 <p:calendar> 组件上禁用特定日期(例如:5 月 15 日或 6 月 23 日)?有最小值和最大值,但我需要禁用特定日期,例如公共假期使用 el 表达式,以便我可以使用动态日期.

Is it possible to disable specific dates (for example: 15th May or 23rd June) on the PrimeFaces 3.5 <p:calendar> component? There is min and max, but I need to disable specific dates like public holidays using el expressions so I can use dynamic dates.

使用 Hieu 的答案,确保您禁用的日期前面没有前导零(例如,'03/03/2013' 应该是 '3/3/2013').

Using Hieu's answer, make sure the dates you disable have NO leading zeros in front (eg. '03/03/2013' should be '3/3/2013').

推荐答案

第一步:编写一个javascript函数来禁用日期列表

Step 1: write a javascript function to disable a list of dates

var disabledDays = ["5-15-2013", "6-23-2013"]; function disableAllTheseDays(date) { var m = date.getMonth(), d = date.getDate(), y = date.getFullYear(); for (i = 0; i < disabledDays.length; i++) { if($.inArray((m+1) + '-' + d + '-' + y,disabledDays) != -1) { return [false]; } } return [true]; }

第二步:使用Primefaces datepicker的beforeShowDay属性

Step 2: use beforeShowDay attribute of Primefaces datepicker

<p:calendar id="pfdate" navigator="true" pattern="MM-dd-yyyy" value="#{day}" beforeShowDay="disableAllTheseDays" showOn="button"/>

更多推荐

禁用 p:calendar 上的特定日期

本文发布于:2023-11-24 12:08:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1625141.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:日期   calendar

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!