0

I can't find a way how to Change the language on a the databox

this are my codesnippets I am loading the language files

<script type="text/javascript" src="../../js/i8n/jquery.mobile.datebox.i18n.en.js"></script>
<script type="text/javascript" src="../../js/i8n/jquery.mobile.datebox.i18n.de.js"></script>

  <div data-role="fieldcontain" id="langSelect">
     <label for="picklang">
      Language</label>
    <select name="picklang" id="picklang" data-native-menu="false">
      <option value="en">[en] English US</option>
      <option value="de" selected="selected">[de] German</option>
    </select>
  </div>
  <div data-role="fieldcontain" id="calendar">
     <input name="startDate" type="date" data-role="datebox" id="startDate" data-options='{"mode": "flipbox", "useLang": "de"}' />
  </div>

I want to change the localisation of the databox according to the selected values of #picklang and I am using therefore the following script code

<script type="text/javascript">
  $(document).delegate('#picklang', 'change', function () {
    var val = $("#picklang option:selected").val();
    alert(val);
    $('#startDate').attr('data-options', '{"mode": "flipbox", "useLang":"' + val + '"}');
  });

A this is the problem. The alert shows the selected value but the databox (=flipbox) shows the same values as before (= after loading the page).

Is there anybody, who can give me advice? Michael

4

1 回答 1

0

这是一个小片段,它不仅会动态加载新选择的语言,还会在页面上的每个日期框上更改为新选择。

$('.opt-pop-lang').live('change', function() {
  newLang = $(this).val();
  $.ajax({
    url: "http://dev.jtsage.com/cdn/datebox/i18n/jquery.mobile.datebox.i18n." + newLang + ".utf8.js",
    success: function(data) {
      eval(data);
      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 = newLang;
      });
    }
  });
});

它可能超出您的需要,但 .useLang 行是改变语言的原因。之前的位是拉入文件并将其注入每个日期框实例。

于 2013-07-11T14:11:00.247 回答