JQuery timepicker时隙没有禁用

时间:2017-11-04 16:06:18

标签: javascript jquery html

我正在尝试在我的jQuery timepicker中禁用一个时间段,但它不会被禁用。我的HTML是:

$( document ).ready(function() {
    $('input[name="datetime"]').timepicker({
        minTime: '10:00am',
        maxTime: '04:40pm',
        interval: '20', // 15 minutes
        disableTimeRanges: [
            ['10:00am', '10:20am'],
            ['4:20pm', '5:00pm']
        ],
        // showDuration: true
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script><link href="https://cdnjs.cloudflare.com/ajax/libs/timepicker/1.3.5/jquery.timepicker.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/timepicker/1.3.5/jquery.timepicker.js"></script>

<input id="timepicker"
       type="text" 
       class = "timepicker"
       name="datetime"
       placeholder = "Time*"
       required/>

我做了一些研究,并尝试了不同的东西,但无法让它发挥作用。有谁知道如何解决这个问题?

1 个答案:

答案 0 :(得分:2)

有两个库,Timepicker for jQueryjQuery Timepicker,我想知道您是否正在使用其中一个并阅读另一个文档。

在这里,我切换到了jQuery库的T​​imepicker,你的代码似乎有效,尽管&#34; interval&#34;成为&#34; step&#34;并取整数(分钟)。

我没有看到对#34; disableTimeRanges&#34;的支持在jQuery Timepicker中

&#13;
&#13;
$( document ).ready(function() {
    $('input[name="datetime"]').timepicker({
    minTime: '10:00am',
    maxTime: '04:40pm',
    step: 20, // 15 minutes
    disableTimeRanges: [
        ['10:00am', '10:20am'],
        ['4:20pm', '5:00pm']
    ],
    // showDuration: true
    });
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script><link href="https://cdnjs.cloudflare.com/ajax/libs/jquery-timepicker/1.10.0/jquery.timepicker.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-timepicker/1.10.0/jquery.timepicker.min.js"></script>


<input id="timepicker"
       type="text" 
       class = "timepicker"
       name="datetime"
       placeholder = "Time*"
       required/>
&#13;
&#13;
&#13;