require.js & jQuery & jQueryUI & datepicker &jquery.ui.datepicker-zh-CN

require.config({
    paths: {
        "jqueryui": '../../../lib/jquery-ui',
        "jquery": "../../../lib/jquery/jquery-1.9.1"
    },
    "shim": {
        "jqueryui/jquery-ui-1.10.3.custom.min": ["jquery"],
        "jqueryui/i18n/jquery.ui.datepicker-zh-CN": ["jqueryui/jquery-ui-1.10.3.custom.min"]
    }
});

require(['jquery', 'jqueryui/jquery-ui-1.10.3.custom.min', 'jqueryui/i18n/jquery.ui.datepicker-zh-CN'], function ($) {
    $(function () {
        $("#datepicker").datepicker({
            changeMonth: true,
            changeYear: true,
            showOn: "button",
            buttonImage: "/css/jquery-ui-themes/base/images/calendar.gif",
            buttonImageOnly: true

        });
    });
   
})

代码的关键点:在shim中定义依赖关系,跑起!

Leave a Reply