【问题标题】:jQuery datepicker not working in jQuery Dialog boxjQuery datepicker 在 jQuery 对话框中不起作用
【发布时间】:2019-09-11 00:49:21
【问题描述】:

jQuery datepicker 在静态页面上工作正常,但我无法让它在 jQuery 对话框页面上工作。这是一个wordpress网站。

我知道所有必要的东西都包括在内,因为它适用于静态页面。对话框页面是通过单击按钮触发的。

这是静态页面上的代码(工作):

<input type="text" class="datepicker" name="datepicker" value="" />

这里是对话框页面上的输入框,是动态创建的(点击输入框没有任何反应):

<input type="text" value="" data_original_for_sale_date="" id="for_sale_date" class="datepicker">

这里是 jQuery 代码:

jQuery(document).ready(function($) {
    $('.datepicker').datepicker({
        dateFormat : 'mm/dd/yy'
    });
});

任何帮助将不胜感激。 (我是新手……)

【问题讨论】:

  • 您能否向我们展示一下用于创建对话框的代码?
  • 当您在其回调中打开对话框时,添加日期选择器代码。发生这种情况是因为当您第一次运行代码时,对话框 datepicker 对 jquery 尚不可见。所以说如果你有一个按钮,你可以调用 opendialog() 或其他东西,然后再次运行 datepicker() 函数而不是 ready() 乐趣

标签: javascript jquery wordpress dialog jquery-ui-datepicker


【解决方案1】:

通过这个更新你的 jquery 代码

    $(document).ready(function($) {
      $('body').on('focus',".datepicker", function(){
        $(this).datepicker({
          dateFormat : 'mm/dd/yy'
        });
      });
    });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多