C# 如何为多个动态文本框启用Google音译(ASP.Net)
下面是在ASP.Net页面中集成Google音译代码的示例代码(随处可见) 但我的问题是,如何在运行时生成的文本框中启用音译?此脚本需要文本框的ID才能应用音译。但我的文本框将在运行时生成 需要此代码行的替代项:C# 如何为多个动态文本框启用Google音译(ASP.Net),c#,javascript,asp.net,google-translate,C#,Javascript,Asp.net,Google Translate,下面是在ASP.Net页面中集成Google音译代码的示例代码(随处可见) 但我的问题是,如何在运行时生成的文本框中启用音译?此脚本需要文本框的ID才能应用音译。但我的文本框将在运行时生成 需要此代码行的替代项: control.maketransiteratable(['transiteratextarea']) //Script Starts here // Load the Google Transliterate API google.load("elements", "1
control.maketransiteratable(['transiteratextarea'])强>
//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);
}
使用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);
首先,必须将所有文本框类名设置为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);
谢谢,很抱歉回复晚了。此外,是否可以始终只允许使用一种语言?我不希望用户能够在语言之间切换。@IshGoel-您正在使用下拉列表加载语言?不完全是这样。语言首选项将存储在数据库中。我希望所有的用户输入总是以一种语言存储在DatbaseThank中。谢谢,很抱歉回复太晚。此外,是否可以始终只允许使用一种语言?我不希望用户能够在语言之间切换。@IshGoel-您正在使用下拉列表加载语言?不完全是这样。语言首选项将存储在数据库中。我希望所有用户输入始终以一种语言存储在datbase中