简体   繁体   English

相对于在另一个文本框中选择月份,如何仅在日期选择器中显示所选月份的日期?

[英]How to display selected month dates only in date picker with respect to selecting month in another text box?

I have 2 text boxes, one is to choose month and year, and another with dates. 我有2个文本框,一个是选择月份和年份,另一个是带日期的。 My both date pickers are working fine, but what I need is when I select month and year from one text box, my date picker for another text box needs to display selected month's dates only. 我的两个日期选择器都工作正常,但是我需要的是从一个文本框中选择月份和年份时,另一个文本框的日期选择器只需要显示所选月份的日期。

Here is my code: 这是我的代码:

 <div class="col-lg-3">
            <label>Month</label>
            <div class="input-group date">
                <input type="text" class="form-control pull-right" id="txtMonth">
                <div class="input-group-addon bg-purple">
                    <i class="fa fa-calendar"></i>
                </div>
            </div>
        </div>
        <div class="col-lg-3">
            <label>Date From</label>
            <div class="input-group date">
                <input type="text" class="form-control pull-right" id="txtDateFrom">
                <div class="input-group-addon bg-purple">
                    <i class="fa fa-calendar"></i>
                </div>
            </div>
        </div>

My Javascript: 我的Javascript:

 <script>
        $(function () {
      $('#txtMonth').datepicker({
                autoclose: true,
                format: "MM yyyy",
                viewMode: "months",
                minViewMode: "months"
            })
            $('#txtDateFrom').datepicker({
                autoclose: true,
                format: 'dd/mm/yyyy'
            })           
        })</script>

This is my month selection textbox. 这是我的月份选择文本框。 If I select Sep 2019 it means, only sep month dates need to display in dates displaying datepicker. 如果我选择2019年9月,则意味着显示日期选择器的日期仅需要显示9月。

在此处输入图片说明

Or if removing those previous and next icons on date calendar also enough for my requirement. 或者,如果删除日期日历上的上一个和下一个图标也足以满足我的要求。

在此处输入图片说明

How can I achieve this? 我该如何实现?

您可以做的是获取您单击的月份的索引,如果两个日期都匹配,则可以将其与日期日历相匹配,您可以专门显示该月日期,或者为年份月份和日期月份日历提供相同的id并运行for循环,如果两项都显示,否则显示隐藏

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM