0

I've derived this from the sample code for a timespinner at http://jqueryui.com/spinner/. I can't get it to work.

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Spinner - Time</title>
<script src="/jquery-2.1.0.min.js"></script>
<script src="/jquery-ui-1.11.2/jquery-ui.min.js"></script>
<script src="/resources/jquery-mousewheel-master/jquery.mousewheel.js"></script>
<script src="/resources/globalize-1.0.0-alpha.10/dist/globalize.js"></script>

<script>
    $.widget( "ui.timespinner", $.ui.spinner, {
            options: { step: 60 * 1000, page: 60 },

            _parse: function( value ) {
                    if ( typeof value === "string" ) {
                            if ( Number( value ) == value ) {
                                    return Number( value );
                            }
                            return +Globalize.parseDate( value );
                    }
                    return value;
            },
            _format: function( value ) {
                    return Globalize.format( new Date(value), "t" );
            }
    });

    $(function() {
            $( "#spinner" ).timespinner();
            $( "#culture" ).change(function() {
                    var current = $( "#spinner" ).timespinner( "value" );
                    Globalize.culture( $(this).val() );
                    $( "#spinner" ).timespinner( "value", current );
            });
    });
</script>
</head>
<body>

<p> <label for="spinner">Time spinner:</label> <input id="spinner" name="spinner" value="08:30 PM"> </p>
<p>
<label for="culture">Select a culture to use for formatting:</label>
<select id="culture">
<option value="en-EN" selected="selected">English</option>
<option value="de-DE">German</option>
</select>
</p>

<div class="demo-description">
<p>
A custom widget extending spinner. Use the Globalization plugin to parse and output
a timestamp, with custom step and page options. Cursor up/down spins minutes, page up/down
spins hours.
</p>
</div>
</body>
</html>

In Chrome, I get: Uncaught TypeError: undefined is not a function

In Firefox, I get: TypeError: Globalize.parsedate is not a function

Both are on the line, return +Globalize.parseDate( value );.

All of the locations of scripts in script tags are correct. I get no other error. The up/down arrows for the spinner are missing.

Am I missing a script?

4

2 回答 2

1

首先,您的脚本不应该在您的脑海中。您应该始终将其加载到您的 dom 下方,因为加载脚本会阻止渲染页面。有关详细信息,请参阅https://developers.google.com/speed/docs/insights/BlockingJS。我尽我所能复制了你的代码,没有任何问题。我建议查看您的 globalize 文件。我对我加载的所有文件都使用了 CDN,并为 globalize.js 文件使用了http://cdnjs.com/libraries/globalize。因此,请仔细检查您的 globalize.js 或提供链接,以便我查看。希望有帮助。

于 2014-11-14T16:31:30.487 回答
0

我使用来自 JqueryUI 站点的 globalize.js 来消除错误。 https://jqueryui.com//resources/demos/external/globalize/globalize.js

于 2017-03-14T22:12:48.553 回答