0

Jquery ui datepicker 在点击输入时不起作用。

main.js

require.config({
    baseUrl: "js",
    paths: {
        html5shiv: "libs/html5shiv",
        jquery: "http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min",
        jqueryui: "http://code.jquery.com/ui/1.10.3/jquery-ui",
        tablesorter: "libs/jquery.tablesorter.min",
        script: "script",
        underscore: "libs/underscore.min",
        backbone: "libs/backbone.min",
        utils: "utils",
        collectorModel: "models/collectorModel",
        collectorCollection: "collections/collectorCollection",
        tollectorRouter: "routers/tollectorRouter",
        edit: "views/collector/tollector_edit",
        index: "views/collector/collector_index",
        neww: "views/collector/collector_new",
        row: "views/collector/collector_row",
        show: "views/collector/collector_show",
        'templates': 'templates'
    },
    shim: {
        jqueryui: {
            deps: ["jquery"],
            exports: "Jqueryui"
        },
        tablesorter: {
            deps: ["jquery"],
            exports: "TableSorter"
        },
        script: {
            deps: ["jquery", "jqueryui", "tablesorter"],
            exports: "Script"
        },
        jqueryui: {
            deps: ["jquery"]
        },
        underscore: {
            exports: "_"
        },
        backbone: {
            deps: ["underscore", "jquery"],
            exports: "Backbone"
        }
    }

});

require(["backbone", "underscore", "collectorCollection", "collectorRouter", "script"],
    function (Backbone, _, CollectorCollection, CollectorRouter) {
        var collectors = new CollectorCollection();
        var router = new CollectorRouter({collectors: collectors});
        Backbone.history.start();
    });

模板:collector_edit.html

input type="text" class="inputs dateInput" name="endDate" placeholder="End date" value="<%= endDate %>

脚本.js

$(document).ready(function () {
    $(".dateInput").datepicker({dateFormat: "dd/mm/yy"});
});

它在使用主干和 RequireJS 之前工作

4

1 回答 1

1

使用 requireJS 时,您的依赖项不再存在于全局范围内,而仅存在于需要它们的模块中。尝试将脚本 JS 更改为:

define(['jqueryui'], function( jqueryui ) {
  $(document).ready(function () {
    $(".dateInput").datepicker({dateFormat: "dd/mm/yy"});
  });

})
于 2013-07-16T02:05:21.490 回答