$(document).on('click','',function(){})无法正常工作 [英] $(document).on('click','',function(){}) not working properly

查看:910
本文介绍了$(document).on('click','',function(){})无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有,正在与$(document).on('click','',function(){});一起工作,但是它没有按我的要求工作 下面是我的代码:

hae, am working with $(document).on('click','',function(){}); but its not working as i want below is my code:

 <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);

上面的代码创建一个月份年份选择器.效果很好.
但是,当我第一次单击时,月份选择器控件什么也不做.当我在其外部单击并再次单击时,它起作用了.
对于第一次点击时如何检测点击事件的任何想法或建议,将受到高度赞赏

The above code creates a month year picker. It works fine.
But when I click for the 1st time, the month picker control does nothing. When I clicked outside it and click on it again, it worked.
Any idea or suggestions on how the click event will be detected on 1st time click will be highly appreciated

推荐答案

尝试 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');
    });
});

演示:小提琴

这篇关于$(document).on('click','',function(){})无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆