我正在尝试使用 jQuery 中的微调器小部件进行全球化工作。我的代码包含的顺序如下:
<script type='text/javascript' src='/js/jquery-2.0.3.min.js'></script>
<script type='text/javascript' src='/js/jquery-migrate-1.2.1.min.js'></script>
<script type='text/javascript' src='/css/jquery/jquery-ui.js'></script>
<script type='text/javascript' src="/resources/js/cldr.js"></script>
<script type='text/javascript' src="/resources/js/cldr/event.js"></script>
<script type='text/javascript' src="/resources/js/cldr/supplemental.js></script>
<script type='text/javascript' src="/resources/js/globalize.js"></script>
<script type='text/javascript' src="/resources/js/globalize/message.js"></script>
<script type='text/javascript' src="/resources/js/globalize/number.js"></script>
<script type='text/javascript' src="/resources/js/globalize/plural.js"></script>
<script type='text/javascript' src="/resources/js/globalize/date.js"></script>
<script type='text/javascript' src="/resources/js/globalize/currency.js"></script>
<script type='text/javascript' src='js/index.js'></script>
我尝试像他们的文档说的那样加载 cldr 的东西,然后我遍历每个微调器容器并根据输入名称应用微调器小部件:
$.when(
$.get( "/resources/js/cldr/main/en/numbers.json" ),
$.get( "/resources/js/cldr/main/en/currencies.json" ),
$.get( "/resources/js/cldr/supplemental/likelySubtags.json" ),
$.get( "/resources/js/cldr/supplemental/numberingSystems.json" ),
$.get( "/resources/js/cldr/supplemental/ordinals.json" ),
$.get( "/resources/js/cldr/supplemental/plurals.json" )
).then(function() {
// Normalize $.get results, we only need the JSON, not the request statuses.
return [].slice.apply( arguments, [ 0 ] ).map(function( result ) {
return result[ 0 ];
});
}).then( Globalize.load ).then(function() {
/**
Add a spinner to each spinner class
*/
$(".spinner").each(function () {
var $S = $(this).children("input");
var name = $(this).attr("name");
switch (name) {
case "one-count":
$S.spinner({
min: 0,
step: 1,
start: 0
});
break;
case "currency-1k-count":
$S.spinner({
min: 0,
step: 1000,
start: 0,
numberFormat: "C"
});
break;
}
});
});
当我在微调器小部件的属性部分中包含 numberFormat 并单击页面上的微调器时,它会抛出一条错误消息:
Uncaught TypeError: Globalize.format is not a function jquery-ui.js(line:12778)
我转到第 12778 行的 jquery-ui.js 文件,我看到它正在调用 Globalize.format。所以我进入了我的 Globalize.js 文件,没有名为 format 的函数……什么给出了?