让我的函数使用jQuery.i18n有问题。它在jQuery(document).ready(function ($) {...});内部工作得很好,而不是在它之外。
jQuery(function($) {
$.i18n().load({
'en': '/path/to/i18n/en.json'
});
});
jQuery(document).ready(function ($) {
function payInfo('example@something.com', '12341234');
console.log('Verification text test: ' + $.i18n('payments.verificationCode')); // works
});
function payInfo(address, invoice) {
// translation does not work here
swal({
title: $.i18n('payments.verificationCode'),
html: $.i18n('payments.verificationDetail', address),
input: 'number',
showCancelButton: true,
confirmButtonText: $.i18n('global.confirm'),
cancelButtonText: $.i18n('global.cancel'),
showLoaderOnConfirm: true,
inputPlaceholder: '0000',
allowOutsideClick: false
})
}错误是TypeError: undefined is not an object (evaluating '$.i18n') -并指向title:行号。允许函数获得i18n翻译的正确方法是什么?
发布于 2020-03-05 17:24:05
您的jQuery没有全局定义。尝试在.ready中添加以下内容
jQuery(document).ready(function ($) {
window.$ = $; // This line
function payInfo('example@something.com', '12341234');
console.log('Verification text test: ' + $.i18n('payments.verificationCode')); // works
});https://stackoverflow.com/questions/60550852
复制相似问题