如何手动设置timepicker

时间:2012-07-28 19:45:57

标签: javascript jquery jquery-ui

我从here下载了时间戳。在切割了很多代码后,我来到了这个简单的例子:

<html>
    <head>
        <title>jQuery.timepickr.js</title>
        <link rel="Stylesheet" media="screen" href="reset.css" />
        <link rel="Stylesheet" media="screen" href="styles.css" />
        <link rel="Stylesheet" media="screen" href="../dist/themes/default/ui.core.css" />
        <link rel="Stylesheet" media="screen" href="../src/css/ui.timepickr.css" />
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.js"></script>
        <script type="text/javascript" src="jquery.utils.js"></script>
        <script type="text/javascript" src="jquery.strings.js"></script>
        <script type="text/javascript" src="jquery.anchorHandler.js"></script>
        <script type="text/javascript" src="jquery.ui.all.js"></script>
        <script type="text/javascript" src="../src/ui.timepickr.js"></script>


        <script type="text/javascript">
            $(function(){
              $('#timepicker').timepickr().focus();
              $('#timepicker').next().find('ol').show().find('li:eq(2)').mouseover();
            });
        </script>
    </head>
    <body id="themeroller">

        <div id="splash">
            <div id="demo">
                <div id="d-demo-wrapper-1" class="demo-wrapper">
                    <input id="timepicker" type="text" value="02:30" class="demo">
                </div>

            </div>
        </div>
    </body>
</html>

我注意到当我尝试从键盘手动设置时间时,数字会自动更改,然后鼠标不在输入字段中。我注意到即使进入原始示例,我也无法手动设置数字。我怎么能解决这个问题?

1 个答案:

答案 0 :(得分:1)

您可以使用val

中的timepickr属性设置默认值
$("#timepickr").timepickr({
            convention: 12,
            format12: "{h:02.d}:{m:02.d} {z:s}",
            rangeMin: $.range(0, 60),
            val: "02:00 am" //set your default time here
        });