0

hae、作業して$(document).on('click','',function(){});いますが、以下は私のコードです。

 <script type="text/javascript">
        $(function () {
            $(document).on('click', '.date-picker', function () {
                $(this).datepicker({
                    changeMonth: true,
                    changeYear: true,
                    showButtonPanel: true,
                    dateFormat: 'MM yy',
                    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).datepicker('setDate', new Date(year, month, 1));
                    }
                });
            });
        });
</script>



table_html = '<td style="min-width: 200px;"><input name="' + control_id + '" id="' + control_id + '" value="' + row_val + '" type="date" data-role="datebox" data-options=\'{"mode": "calbox", "useClearButton": true}\' ></td>';
  $('#variables').append(table_html);

上記のコードは、月年ピッカーを作成します。それは正常に動作します。
しかし、初めてクリックすると、月ピッカー コントロールは何もしません。その外側をクリックしてもう一度クリックすると、うまくいきました。
初めてのクリックでクリックイベントがどのように検出されるかについてのアイデアや提案は高く評価されます

4

1 に答える 1

1

show() を試す

$(function () {
    $(document).on('click', '.date-picker', function () {
        var datepicker = $(this).data('uidatepicker');
        if(datepicker) return;
        $(this).datepicker({
            changeMonth: true,
            changeYear: true,
            showButtonPanel: true,
            dateFormat: 'MM yy',
            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).datepicker('setDate', new Date(year, month, 1));
            }
        }).datepicker('show');
    });
});

デモ:フィドル

于 2013-10-16T09:12:45.810 に答える