如何让bootstrap时间选择器关闭?

时间:2015-04-07 15:24:34

标签: javascript jquery twitter-bootstrap knockout.js

如何在设定时间后关闭第二次选择器?即使我点击网页上的提交按钮,它也会保持打开状态。

http://jsfiddle.net/jkittell/z485769h/1/

HTML code:

<div class="container">
     <h1>Select Two Times</h1>

    <form>
        <br />
        <input type="text" data-bind="value: startTime" name="start_time" class="timepicker" placeholder="h:mm PM" data-default-time="false"></input>
        <input type="text" data-bind="value: endTime" name="start_time" class="timepicker" placeholder="h:mm PM" data-default-time="false"></input>

    </form>
     <button data-bind="click: submit">Click Me</button>
    <br />
    <p>You selected: <span data-bind="text: timeSpan"></span></p>
</div>

Knockout.js代码:

$(function () {
    $('.timepicker').timepicker();
    function ViewModel() {
        var self = this;
        self.startTime = ko.observable();
        self.endTime = ko.observable();
        self.timeSpan = ko.computed(function () {
            return self.startTime() + " - " + self.endTime();
        }, this);

        self.submit = function () {
            alert("Time submitted");
        };
    }

    ko.applyBindings(new ViewModel());

});

1 个答案:

答案 0 :(得分:0)

$('.bootstrap-timepicker-widget').removeClass('open');

DEMO:http://jsfiddle.net/z485769h/2/