在文本中输入输入字段

时间:2017-09-08 07:21:52

标签: javascript jquery json angular

在下面的代码中,我使用Google音译在文本字段中输入印度语。我有两条路线,我正在传递两个不同页面的ID。当我加载默认页面时,Google音译正在运行。但是,当我点击并更改我的路线时,Google音译会出错。我想使用JSON传递数据库中的类型值,但我的JSON只接受英文版的值。

enter image description here



// Load the Google Transliterate API
google.load("elements", "1", {
  packages: "transliteration"
});

function onLoad() {
  var options = {
    sourceLanguage: google.elements.transliteration.LanguageCode.ENGLISH,
    destinationLanguage: [google.elements.transliteration.LanguageCode.MARATHI],
    shortcutKey: 'ctrl+g',
    transliterationEnabled: true
  };

  // Create an instance on TransliterationControl with the required
  // options.

  var control = new google.elements.transliteration.TransliterationControl(options);
  // control.makeTransliteratable(['firstName']);
  control.makeTransliteratable(['userName', 'firstName']);
}
google.setOnLoadCallback(onLoad);

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script type="text/javascript" src="https://www.google.com/jsapi">
</script>


<div class="input-group mb-1 row loginInput">
  <span class="input-group-addon"><i class="icon-email">@</i></span>
  <input type="text" class="form-control" id="userName" placeholder="{{ 'Login.E-mail ID / Mobile' | translate }} " [(ngModel)]="loginModel.userName" name="userName" required #userName="ngModel">
</div>


<div class="input-group mb-1">
  <span class="input-group-addon"><i class="icon-user"></i></span>
  <input type="text" id="firstName" class="form-control" placeholder="{{'Registration.First Name' | translate}}" [(ngModel)]="registrationModule.firstName" name="firstName" pattern="[a-zA-Z][a-zA-Z ]+" #firstName="ngModel" required>
</div>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

    google.load("elements", "1", { packages: "transliteration" });

    function OnLoad() {
        var content = document.getElementById('content');

        var options = {
            sourceLanguage:
          google.elements.transliteration.LanguageCode.ENGLISH,
            destinationLanguage:
          [google.elements.transliteration.LanguageCode.MARATHI],
            shortcutKey: 'ctrl+g',
            transliterationEnabled: true
        };
        var control = new google.elements.transliteration.TransliterationControl(options);
        control.makeTransliteratable(['userName']);
     control.makeTransliteratable(['firstName']);
    }
    google.setOnLoadCallback(OnLoad);
</script>