javascript - p :calendar for only month and year

标签 javascript css primefaces datepicker calendar

我想在同一页面上有两个不同的 primefaces 日历。

一个日历包含日期,第二个日历仅包含月份和年份。

我使用了下面的 javascript 和 css 只有月份和年份的日历。 它工作正常,但其他日历也受到影响,并且由于以下 CSS 样式而无法显示日期。 有没有办法将样式应用于特定日历而不是全部?

javascript :-

$(".monthPicker").datepicker({    
        dateFormat: 'M yy',
        changeMonth: true,
        changeYear: true,
        showButtonPanel: true,
        maxDate: $.now() ,

        onClose: function(dateText, inst) {

            var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
            var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
            $(this).val($.datepicker.formatDate('M yy', new Date(year,month, 1)));
        }
    });
    $( ".monthPicker" ).datepicker( "option", "maxDate", new Date() );  
    $(".monthPicker").focus(function () {
        $(".ui-datepicker-calendar").hide();
        $("#ui-datepicker-div").position({
            my: "center top",
            at: "center bottom",
            of: $(this)
        });
    });

CSS:-

.ui-datepicker-calendar {
   display: none;
 }

最佳答案

只需将另一个标记类附加到此类日期选择器,如下所示:

$(".monthPicker").datepicker({
        beforeShow : function(input, instance){
            instance.dpDiv.addClass("month-picker")
        }
});
.month-picker
{
  border: 2px solid pink
}
<script
  src="https://code.jquery.com/jquery-2.2.4.min.js"
  integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="
  crossorigin="anonymous"></script>
<script
  src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"
  integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU="
  crossorigin="anonymous"></script>

<input type="text" class="monthPicker" />

现在您可以选择:

.ui-datepicker.month-picker

关于javascript - p :calendar for only month and year,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41015664/

相关文章:

javascript - 在for循环javascript中显示唯一值

javascript - OKZoom 插件不适用于带有 svg 过滤器的图像

jquery - 检测 html5 中列的位置

html - 将子 div 标签水平放置,尽管父 div 标签宽度

javascript - 正则表达式,用于匹配包含一个单词但不包含另一个单词的URL

html - 使用表格布局时列宽错误 :fixed

java - 如何在 liferay 6.2 中的每个新选项卡上实例化新的 session 范围 Controller ,同时保留旧选项卡

java - <f : validator> and ajax in JSF 问题

javax.faces.FacesException : Expression Error: Named Object: player not found

javascript - Jquery 在 div 中即时写入