codeigniter中的日期选择器

时间:2016-06-15 08:27:01

标签: javascript php twitter-bootstrap codeigniter

我想在Codeigniter中使用Datepicker,但我遇到了问题。这是我的代码:

<div class="form-group">
    <!--- date picker--->
    <label for="dtp_input2" class="col-sm-2 col-sm-2 control-label">Tanggal Berita</label>
    <div class=”input-append date” id=”datepicker” data-date=”” data-date-format=”dd-mm-yyyy” >
        <input class=”span2″ size=”16″ type=”text” value=”” disabled>
        <span class=”add-on”><i class=”icon-th”></i></span>
    </div>

    <script>
        $(‘#datepicker’).datepicker();
    </script>
    <input type="hidden" id="datepicker" value=""/>
</div>

脚本:

<script src="<?php echo base_url(); ?>assets/js/chart-master/Chart.js"></script>
<script rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>assets/js/bootstrap-datetimepicker.id.js"></script>
<script rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>assets/js/bootstrap-datetimepicker.js"></script>
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>assets/css/bootstrap-datetimepicker.css">
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
  <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<script type="text/javascript">
    $('.datepicker').datetimepicker({
        language:  'id',
        weekStart: 1,
        todayBtn:  1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        minView: 2,
        forceParse: 0
    });
</script>

2 个答案:

答案 0 :(得分:0)

使用正确的"引号更改您的代码,如

<div class="input-append date" id="datepicker" data-date="" data-date-format="dd-mm-yyyy" >
    <input class="span2" size="16" type="text" value="" disabled>
    <span class="add-on"><i class="icon-th"></i></span>
</div>

<script type="text/javascript">
    $("#datepicker’).datepicker();
</script>

答案 1 :(得分:0)

如果你有两个同名的id,它将无法工作。使用其他ID,然后根据您的ID决定使用datepicker或datetimepicker。