我正在寻找一种以编程方式更改jqm DateBox插件语言的方法。 我已将语言文件包含在标题部分中:
<script type="text/javascript" src="../Scripts/jqmDateBox/jqm-datebox.core.min.js"></script>
<script type="text/javascript" src="../Scripts/jqmDateBox/jqm-datebox.mode.flipbox.min.js"></script>
<script type="text/javascript" src="../Scripts/jqmDateBox/jquery.mousewheel.min.js"></script>
<script type="text/javascript" src="../Scripts/jqmDateBox/jquery.mobile.datebox.i18n.de.utf8.js"></script>
<script type="text/javascript" src="../Scripts/jqmDateBox/jquery.mobile.datebox.i18n.en.utf8.js"></script>
<script type="text/javascript" src="../Scripts/jqmDateBox/jquery.mobile.datebox.i18n.fr.utf8.js"></script>
<script type="text/javascript" src="../Scripts/jqmDateBox/jquery.mobile.datebox.i18n.it.utf8.js"></script>
我尝试使用以下代码段(changeing language files in JTSage Date and Time Picker plugin for jQueryMobile)更改语言:
var x = $.mobile.datebox.prototype.options.lang[newLang];
$(document).find('[data-role=datebox]').each(function () {
$(this).data('mobileDatebox').options.lang[newLang] = x;
$(this).data('mobileDatebox').options.useLang = "de";
});
但这给了我以下例外:
JavaScript runtime error: Unable to get property 'options' of undefined or null reference.
如何以编程方式更改jqm DateBox插件的语言?
答案 0 :(得分:1)
我找到了改变语言的方法......
setDateInputOptions($("#dateInput"), "de");
function setDateInputOptions(input, language) {
input.datebox("option", {
"mode": "flipbox",
"useFocus": true,
"useButton": false,
"useNewStyle": true,
"overrideDateFormat": "%d.%m.%Y",
"overrideDateFieldOrder": ["d", "m", "y"],
"useLang": language
});
}