【问题标题】:Invoking Bootstrap Datetimepicker through class rather than id通过类而不是 id 调用 Bootstrap Datetimepicker
【发布时间】:2017-09-15 03:16:45
【问题描述】:

我很想知道如何通过类属性而不是 id 来调用引导程序 datetimepicker (More info)。

这是我的 HTML

<input class="form-control dateclass" placeholder="Date of visit 1" />
<input class="form-control dateclass" placeholder="Date of visit 2" />
<input class="form-control dateclass" placeholder="Date of visit 3" />

现在,我想像这样调用 datetimepicker:

$('.dateclass').datetimepicker({
        format: 'YYYY-MM-DD',
        showClose: true,
        widgetPositioning: {
            horizontal: 'left',
            vertical: 'bottom'
        }
    });

但这不起作用。 html 中的输入框实际上是通过剔除动态填充的,因此我无法使用 id。

我怎样才能完成这项任务?

【问题讨论】:

标签: javascript jquery twitter-bootstrap knockout.js datetimepicker


【解决方案1】:

试试Template Binding

您可以将您的代码放入淘汰赛生命周期的 afterRender 挂钩中。 不是常规的 knockoutjs 用户。

【讨论】:

    【解决方案2】:

    我猜你只需要按类名而不是 id 打开一个日期选择器。如果是这种情况,您可以这样做。

    $('.dateclass').click(function () {
        $(this).datetimepicker({
              //your definations
            }
        });
    });
    

    上述代码的作用是监听被点击的类的点击事件,然后选择该dom并触发该dom上的datetimepicker。

    【讨论】:

      猜你喜欢
      • 2012-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-18
      • 2018-06-16
      • 2011-11-30
      相关资源
      最近更新 更多