【问题标题】:Date Picker Date change while using Google Translator使用谷歌翻译时日期选择器日期更改
【发布时间】:2013-06-05 12:16:32
【问题描述】:

我正在使用日期选择器作为签入日期。

我在我的网站上使用谷歌翻译。

所以当我将语言从英文更改为中文或任何其他语言时, 日期选择器值变为NaN/NaN/NaN。日期选择器格式为mm/dd/yyyy

【问题讨论】:

    标签: jquery


    【解决方案1】:

    jquery.ui.datepicker.js 中添加notranslate 类和ui-helper-clearfix 类。

    【讨论】:

    【解决方案2】:

    当您不能/不想更改 jQuery UI 日期选择器代码时,您还可以使用 beforeShow 回调添加 notranslate 类:

    beforeShow: function(input, inst) {
        inst.dpDiv.addClass('notranslate');
    }
    

    使用版本 1.12.0 测试

    【讨论】:

      【解决方案3】:

      首先你需要搜索这个

      ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all

      在您的 jquery ui JS 中,或者您可以搜索整个项目,然后将所有出现的地方替换为

      ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all notranslate.

      关键字notranslate 将阻止您的日历翻译。

      【讨论】:

        【解决方案4】:

        我也遇到了日期选择器的问题。它正在用 Nan/Nan/Nan 替换日期。我在网站上使用谷歌语言翻译器,我禁用了它,它开始正常工作。

        【讨论】:

          【解决方案5】:

          如果我们使用谷歌翻译使用日期选择器翻译表单,则在完成翻译后,该字段可能会显示 NaN/NaN/NaN 而不是所选日期。

          Google 有解决方案。我们需要向字段或其父元素添加 notranslate。 Google 翻译从不考虑翻译此类中的内容。

          <input type="text" class="datepicker notranslate">
          

          如果我们使用 jQuery & jQuery UI datepicker,我们也可以在 datepicker 的初始化过程中使用 jQuery 添加类。

          $(function() {
              $(".datepicker").datepicker();
              $('.ui-datepicker').addClass('notranslate');
          });
          

          【讨论】:

            【解决方案6】:

            添加焦点事件 答案 1

            $(function () {
            $('.datepicker').on('focus', function () {
                $('.datepicker').addClass('notranslate');
            });
            

            });

            或 答案 2 添加这个js文件 http://code.jquery.com/ui/1.11.4/jquery-ui.js

            【讨论】:

              猜你喜欢
              • 2013-06-12
              • 1970-01-01
              • 1970-01-01
              • 2010-10-06
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2013-11-28
              相关资源
              最近更新 更多