![](/img/trans.png)
[英]why regex is only validating one character from the field and not all entered
[英]Copy only the entered character from one text box to another
我有兩個文本框#textBox1
和#textBox2
。
用戶將輸入到#textBox1
並且所有值都需要自動復制到#textBox2
[我在這里有onkeyup
事件]。 只從一個復制到另一個就沒有問題。 我的要求是,一旦用戶按下space
或從#textBox1
enter
我的英語單詞,它將轉換為本地語言,但我只需要#textBox2
上的英語版本。
請參閱以下示例:
textBox1 = "Bhuwan", textBox2="Bhuwan"
一旦用戶按下空格鍵
textBox1 = "भुवन ", textBox2="Bhuwan "
textBox1 = "भुवन Gautam", textBox2="Bhuwan Gautam"
再次按下用戶空格鍵
textBox1 = "भुवन गौतम", textBox2="Bhuwan Gautam"
我使用了以下內容,但如果用戶在#textBox1
上使用退格鍵,則此操作不完整。
$("#textBox1").keyup(function(e) {
$('#textBox2').val($('#textBox2').val()+String.fromCharCode(e.which));
});
我知道有更好的解決方案。 如何通過jquery或javascript實現此目的?
我想你可以通過這個解決方案請點擊
我將強調一些要點。
使用Google翻譯API。 易於使用。 例如,以下將西班牙語翻譯為英語。 要與其他語言進行互譯,只需更改“ es”和“ en”
google.load("language", "1");
function initialize() {
var content = document.getElementById('content');
content.innerHTML = '<div id="text">Hola, me alegro mucho de verte.<\/div><div id="translation"/>';
var text = document.getElementById("text").innerHTML;
google.language.translate(text, 'es', 'en', function(result) {
var translated = document.getElementById("translation");
if (result.translation) {
translated.innerHTML = result.translation;
}
});
}
google.setOnLoadCallback(initialize);
試試Google翻譯 : http : //code.google.com/apis/language/translate/overview.html
您也可以使用此JQuery插件 http://www.openxrest.com/translatejs
您可以使用bing翻譯 .. http://setahost.com/bing-translate-api-with-jquery-ajax/ Bing api仍然免費
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.