我如何获得源为我的事件,与Bootstrap 3 DateTimePicker

How do I get the source for my events, with Bootstrap 3 DateTimePicker

本文关键字:Bootstrap DateTimePicker 事件 我的 何获得      更新时间:2023-09-26

我使用Bootstrap 3 DateTimePicker,但有一些小问题。

基本上,在dp上。显示事件,我如何获得源代码控制?据我所知,没有随事件发送参数,所以我很难弄清楚实际显示的是哪个控件。

(我的应用程序中有许多选择器)

标准的JQuery会告诉我我可以使用e. target,但是没有e与事件一起发送:(

我该如何处理?

您可以将处理程序附加到您的日期拾取器集合

$('.datepicker').on('dp.show', function() {
    // this here will refer to the currently showing widget
    console.log(this);
});

这是处理事件的标准引导方式。

编辑:如果您阅读源代码,事件将绑定到初始化日期选择器的元素:https://github.com/Eonasdan/bootstrap-datetimepicker/blob/master/src/js/bootstrap-datetimepicker.js#L451

您可以使用下面的事件

  <script src="//code.jquery.com/jquery-2.1.3.js" type="text/javascript"></script>
  <link href="/css/result-light.css" type="text/css" rel="stylesheet">
  <script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js" type="text/javascript"></script>
  <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" type="text/css" rel="stylesheet">
  <link href="//cdn.rawgit.com/Eonasdan/bootstrap-datetimepicker/e8bddc60e73c1ec2475f827be36e1957af72e2ea/build/css/bootstrap-datetimepicker.css" type="text/css" rel="stylesheet">
  <script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment-with-locales.js" type="text/javascript"></script>
  <script src="//cdn.rawgit.com/Eonasdan/bootstrap-datetimepicker/e8bddc60e73c1ec2475f827be36e1957af72e2ea/src/js/bootstrap-datetimepicker.js" type="text/javascript"></script>
<script type="text/javascript">
    //&lt;![CDATA[
    $(function() {
      $('#datetimepicker6').datetimepicker();
      $("#datetimepicker6").on("dp.show", function(e) {
        console.log(e);// e is event and use console to explore other options
      });
    }); //]]&gt;
  </script>
</head>
<body>
  <div class="input-group ">
    <input type="text" class="form-control" id="datetimepicker6">
  </div>
</body>
</html>