模态上的Bootstrap显示datepicker

时间:2017-07-05 22:01:20

标签: javascript php jquery twitter-bootstrap datepicker

我正在尝试使用在模态上显示的datepicker。但我的代码不起作用。我已经使用 .datepicker {z-index:1151;} 而且它也没有用,有人可以帮我在bootstrap模式上显示datepicker吗?感谢

这是我的代码,

按钮(在edit.php中):

<a href="#detail" id="custId" data-toggle="modal" data-id="'.$row["id"].'" class="btn btn-success btn-sm" role="button" title="Detail"><i class="glyphicon glyphicon-eye-open"></i></a>

模态(在index.php中):

<div class="modal fade" id="edit" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">Edit Costumer</h4>
            </div>
            <div class="modal-body">
                <div class="fetched-data"></div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-danger" data-dismiss="modal">Keluar</button>
            </div>
        </div>
    </div>
</div>

JS for modal(在index.php中):

<script type="text/javascript">
    $(document).ready(function(){
        $('#edit').on('show.bs.modal', function (e) {
            var rowid = $(e.relatedTarget).data('id');
            //menggunakan fungsi ajax untuk pengambilan data
            $.ajax({
                type : 'post',
                url : 'edit.php',
                data :  'rowid='+ rowid,
                success : function(data){
                $('.fetched-data').html(data);//menampilkan data ke dalam modal
                }
            });
         });
    });
</script>

用于Datepicker的JS(在index.php中):

<script type='text/javascript'>
    $(function(){
        $('.input-group.date').datepicker({
            calendarWeeks: true,
            todayHighlight: true,
            autoclose: true
        });  
    });
</script>

1 个答案:

答案 0 :(得分:0)

对引用现有input元素的jQuery对象使用datepicker方法。见下面的例子。

&#13;
&#13;
$(function() {
  $('.fetched-date input').datepicker({
    calendarWeeks: true,
    todayHighlight: true,
    autoclose: true
  });
});
&#13;
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.7.0/css/bootstrap-datepicker.min.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.7.0/js/bootstrap-datepicker.min.js"></script>

<!-- body -->
<div class="modal fade" id="edit" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Edit Costumer</h4>
      </div>
      <div class="modal-body">
        <div class="input-group fetched-date">
          <input type="text" class="form-control" value="07/07/2017">
          <div class="input-group-addon">
            <span class="glyphicon glyphicon-th"></span>
          </div>
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-danger" data-dismiss="modal">Keluar</button>
      </div>
    </div>
  </div>
</div>

<button type="button" class="btn btn-success btn-sm" data-toggle="modal" data-target="#edit" title="Detail">
  <i class="glyphicon glyphicon-eye-open"></i>
</button>
&#13;
&#13;
&#13;