gpt4 book ai didi

javascript - 如何根据 Class 而不是 Id 进行 Google 音译

转载 作者:数据小太阳 更新时间:2023-10-29 03:54:48 25 4
gpt4 key购买 nike

我正在做一个基于泰米尔语的 Web 应用程序。在我的应用程序中,我使用动态字段来添加用户详细信息。那么,动态字段有多个 ID 如何做到这一点或如何使用基于类的 Google 音译?

<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
// Load the Google Transliteration API
google.load("elements", "1", {
packages: "transliteration"
});

function onLoad() {
var options = {
sourceLanguage: 'en',
destinationLanguage: 'ta',
shortcutKey: 'ctrl+m',
transliterationEnabled: true
};

// Create an instance on TransliterationControl with the required
var control = new google.elements.transliteration.TransliterationControl(options);

// Enable transliteration in the textfields with the given ids.
var ids = ['temrorary_address', 'permanant_address', 'bankbranch', 'member_name', 'father_husband', 'workingoffice_address', ];
control.makeTransliteratable(ids);

// Show the transliteration control which can be used to toggle between
// English and Hindi and also choose other destination language.
control.showControl('translControl');
}
google.setOnLoadCallback(onLoad);
</script>

最佳答案

makeTransliteratable 输入不仅可以是 id 数组,还可以是元素引用。所以你可以这样写:

// Enable transliteration in the textfields with the given Class.
var elements = document.getElementsByClassName('Type-Your-Class-Here');
control.makeTransliteratable(elements);

但是,如果您动态添加字段,那将无济于事。对于动态添加的字段,每次添加新字段时都必须调用 control.makeTransliteratable

关于javascript - 如何根据 Class 而不是 Id 进行 Google 音译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44469922/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com