【问题标题】:Multiple ajax generated input with datepicker having month and year only多个 ajax 生成的输入,日期选择器只有月份和年份
【发布时间】:2017-09-21 06:41:59
【问题描述】:

我想获得多个带有dateRange 的输入框,只有使用 ajax 技术的月份和年份。

在我的项目中,我需要从 ajax 调用中动态获取多个输入框。每个输入框都应该有日期范围drop-down日历,只有选择月份和年份的选项。

在同一页面 (abc.php) 上,使用以下代码可以正常工作:

 <input type="text" name='startMonth' class="monthyear" />

 <link href="../asset/datepicker3/datepicker3.css" rel="stylesheet" type="text/css" />
 <script src="../asset/datepicker3/bootstrap-datepicker.js" type="text/javascript"></script>

但是当我从 ajax 调用时它没有得到响应,代码如下:

abc.php:

<button type="button" onclick="getInputBoxes()">Get Input Boxes</button>
<div id="block_input"></div>
<script>
    function getInputBoxes(){
            $.post('ajx_abc.php', { }, 
        function(data, status){
                    $('#block_input').html(data);
                    $("#block_input").html(data).find(".monthyear").datepicker();
            });
    }
</script>

Ajax 文件 (ajx_abc.php):

<?php
for($i=1; $i<=5; $i++){
    <input type="text" name="cust_mnth[]" class="monthyear" />
}
?>

【问题讨论】:

    标签: jquery ajax datepicker


    【解决方案1】:

    试试这个。首先填充所有输入日期选择器。 然后初始化它们;

    $(document).ready(function(){
        $(document).find("#block_input .monthyear").datepicker();
    });
    

    【讨论】:

    • 不! :( 显示包括日期在内的整个日历。但我只需要月份和年份。
    【解决方案2】:

    知道了! :)

    只需要传递两个参数minViewMode & format

    abc.php:

    <button type="button" onclick="getInputBoxes()">Get Input Boxes</button>
    <div id="block_input"></div>
    <script>
        function getInputBoxes(){
                $.post('ajx_abc.php', { }, 
            function(data, status){
                        $('#block_input').html(data);
                        $("#block_input").html(data).find(".monthyear").datepicker({
                            minViewMode: 1,// 0-normal date calendar; 1-month; 2-year
                            format: 'yyyy-mm',
                            startDate: "0m", // from current month
                            endDate: "+2m" // till next 2 months
                        });
                });
        }
    </script>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-06
      • 1970-01-01
      • 2021-12-15
      • 1970-01-01
      • 1970-01-01
      • 2011-05-04
      相关资源
      最近更新 更多