如何为多个动态文本框启用Google Transliteration(ASP.Net)

以下是在ASP.Net Pages中集成Google Transliteration代码的示例(随处可用)代码。

但我的问题是,如何在运行时生成的TextBoxes中启用音译? 此脚本需要文本框的ID才能应用Transliteration。 但我的文本框将在运行时生成。

需要替代此代码行:
control.makeTransliteratable([ ‘transliterateTextarea’]);

//Script Starts 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.HINDI], shortcutKey: 'ctrl+g', transliterationEnabled: true }; // Create an instance on TransliterationControl with the required // options. var control = new google.elements.transliteration.TransliterationControl(options); // Enable transliteration in the textbox with id // 'transliterateTextarea'. control.makeTransliteratable(['transliterateTextarea']); } google.setOnLoadCallback(onLoad); //End here 

使用RegisterStartupScript。 完全加载页面后将执行RegisterStartupScript。

 function EnableTransalation(ctrlId) { //Script Starts 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.HINDI], shortcutKey: 'ctrl+g', transliterationEnabled: true }; // Create an instance on TransliterationControl with the required // options. var control = new google.elements.transliteration.TransliterationControl(options); // Enable transliteration in the textbox with id // 'transliterateTextarea'. control.makeTransliteratable(["'" + ctrlId + "'"]); } google.setOnLoadCallback(onLoad); //End here } 

在后面的代码中,

 protected override void OnPreRender(EventArgs e) { Page.ClientScript.RegisterStartupScript(GetType(), "EnableTransalation", "EnableTransalation('" + ctrl.ClientID + "')", true); } 

首先,您必须将所有文本框类名称设置为hindiFont。

使用此代码:

 google.load("elements", "1", { packages: "transliteration" }); function onLoad() { var options = { sourceLanguage: [google.elements.transliteration.LanguageCode.ENGLISH], destinationLanguage: [google.elements.transliteration.LanguageCode.HINDI], transliterationEnabled: true, shortcutKey: 'ctrl+g' }; var control = new google.elements.transliteration.TransliterationControl(options); $('.hindiFont').each(function(){ var id = this.id; control.makeTransliteratable([id]); }) } google.setOnLoadCallback(onLoad);