dongshiqin1352 2018-06-14 15:19
浏览 101

在PHP中循环并合并Datetimepicker

I'm using datetimepicker javascript for bootstrap. The instance works if there is only one input field or if it's the first of multiple. But if there are multiple fields, the others don't work.

The widget is created from a foreach loop in php so foreach record it gives a new section with title, expiration date and a datetimepicker field to create a new date. However, if I hit the calendar icon of the 2nd or 3rd datepicker item it just activates the popover calendar for the first one.

How can i properly incorporate this into the loop so that each field has it's own input for datetimepicker?

<?php foreach($v as $k=>$n): ?>
<!--Body of the Modal for expired displays-->
<br>
<h6><?php echo $n['Type'] ?></h6>
<h6>Date/Time Expiring: <?php echo $n["Expiration"] ?></h6>
<h6>Set New Expiration:</h6>
  <div class="form-group">
    <div class="input-group date" id="datetimepicker1" data-target-input="nearest">
      <input type="text" class="form-control datetimepicker-input" data-target="#datetimepicker1"/>
      <span class="input-group-addon" data-target="#datetimepicker1" data-toggle="datetimepicker">
          <span class="fa fa-calendar"></span>
      </span>
    </div>
  </div>                 
<?php endforeach; ?>

<script type="text/javascript">
$(function () {
  $('#datetimepicker1').datetimepicker({
     icons: {
                  time: "fa fa-clock-o",
                  date: "fa fa-calendar",
                  up: "fa fa-arrow-up",
                  down: "fa fa-arrow-down"
              }
  });
});
</script>

UPDATE:

<div class="form-group">
              <div class=" datepicker input-group date"  data-target-input="nearest">
                <input type="text" class="form-control datetimepicker-input" data-target=".datepicker"/>
                <span class="input-group-addon" data-target=".datepicker" data-toggle="datetimepicker">
                    <span class="fa fa-calendar"></span>
                </span>
              </div>
            </div>
<script type="text/javascript">
$('.datepicker').each(function(){
  $(this).datetimepicker();
   icons: {
                time: "fa fa-clock-o",
                date: "fa fa-calendar",
                up: "fa fa-arrow-up",
                down: "fa fa-arrow-down"
            }
  });

</script>
  • 写回答

2条回答 默认 最新

  • dongyu4908 2018-06-14 15:34
    关注

    You have several div's with the same ID. This is not correct.

    <?php foreach($v as $k=>$n): ?>
    <!--Body of the Modal for expired displays-->
    <br>
    <h6><?php echo $n['Type'] ?></h6>
    <h6>Date/Time Expiring: <?php echo $n["Expiration"] ?></h6>
    <h6>Set New Expiration:</h6>
      <div class="form-group">
        <div class="input-group date datetimepicker1" data-target-input="nearest">
          <input type="text" class="form-control datetimepicker-input" data-target="#datetimepicker1"/>
          <span class="input-group-addon" data-target="#datetimepicker1" data-toggle="datetimepicker">
              <span class="fa fa-calendar"></span>
          </span>
        </div>
      </div>                 
    <?php endforeach; ?>
    
    <script type="text/javascript">
    $(function () {
      $('.datetimepicker1').datetimepicker({
         icons: {
                      time: "fa fa-clock-o",
                      date: "fa fa-calendar",
                      up: "fa fa-arrow-up",
                      down: "fa fa-arrow-down"
                  }
      });
    });
    </script>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料