如何在同一页面上运行多个datetimepickers?

时间:2015-12-07 11:45:25

标签: jquery datepicker datetimepicker

jQuery有很多日期和时间插件,但是在尝试运行此插件的多个实例时似乎存在问题。

我的代码:

    //date and time
    $('.datepick').datepicker({
        format: "yyyy-mm-dd",
        language: 'nb',
        weekStart: 1,
        autoclose: true,
        todayHighlight: true
    }); 

    $('.timepick').timepicker({
        minuteStep: 15,
        showInputs: false,
        disableFocus: true,
        showMeridian: false
    });

一些html:

<div class="col-md-2">
<label class="text-muted">Date</label>
<div class="input-group date">
    <input type="text" class="form-control datepick" name="date">
    <span class="input-group-addon"><i class="fa fa-calendar fa-lg"></i></span>
</div>

<div class="col-md-2">
    <label class="text-muted">TIME</label>
    <div class="input-group date">
        <input type="text" class="form-control timepick" name="time">
        <span class="input-group-addon"><i class="fa fa-clock-o fa-lg"></i></span>
    </div>                  
</div>  

我有一个脚本可以在单击添加按钮时复制此代码;问题是datetimepickers不能用于添加到表单的字段。

有没有人有指针如何在所有具有类datepick / timepick的inputfileds上显示datetimepickers?

更新 接缝这段代码就行了。

    $("body").delegate("input[type=text].datepick", "focusin", function(){
          $('.datepick').datepicker({
            format: "yyyy-mm-dd",
            language: 'nb',
            weekStart: 1,
            autoclose: true,
            todayHighlight: true
        }); 
    }); 

    $("body").delegate("input[type=text].timepick", "focusin", function(){
        $('.timepick').timepicker({
            minuteStep: 15,
            showInputs: false,
            disableFocus: true,
            showMeridian: false
        });
    });

0 个答案:

没有答案