簡體   English   中英

僅將輸入的字符從一個文本框復制到另一個文本框

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM