简体   繁体   English

仅将输入的字符从一个文本框复制到另一个文本框

[英]Copy only the entered character from one text box to another

I have two text box #textBox1 and #textBox2 . 我有两个文本框#textBox1#textBox2

User will input to #textBox1 and all the values need to be copied to #textBox2 automatically [I have a onkeyup event here]. 用户将输入到#textBox1并且所有值都需要自动复制到#textBox2 [我在这里有onkeyup事件]。 Only copy and paste from one to another is not a problem. 只从一个复制到另一个就没有问题。 My requirement is once user press space or enter my English word from #textBox1 will convert to local language but I need only the English version on #textBox2 . 我的要求是,一旦用户按下space或从#textBox1 enter我的英语单词,它将转换为本地语言,但我只需要#textBox2上的英语版本。

See the example below: 请参阅以下示例:

textBox1 = "Bhuwan", textBox2="Bhuwan"

once user press space bar 一旦用户按下空格键

textBox1 = "भुवन ", textBox2="Bhuwan "

textBox1 = "भुवन Gautam", textBox2="Bhuwan Gautam"

Again once user press space bar 再次按下用户空格键

textBox1 = "भुवन गौतम", textBox2="Bhuwan Gautam"

I have used the following but it is not complete if the user use backspace on #textBox1 . 我使用了以下内容,但如果用户在#textBox1上使用退格键,则此操作不完整。

$("#textBox1").keyup(function(e) {
            $('#textBox2').val($('#textBox2').val()+String.fromCharCode(e.which));
});

I know there is a better solution. 我知道有更好的解决方案。 How do I achieve this either from jquery or javascript ? 如何通过jquery或javascript实现此目的?

I think You can go through this solution Click 我想你可以通过这个解决方案请点击

I will highlight some points. 我将强调一些要点。

Use Google translation API. 使用Google翻译API。 Easy to use. 易于使用。 For example the following translates Spanish to English. 例如,以下将西班牙语翻译为英语。 To translate from and to other languages, simply change 'es' and 'en' 要与其他语言进行互译,只需更改“ 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);

try google translate : http://code.google.com/apis/language/translate/overview.html 试试Google翻译http : //code.google.com/apis/language/translate/overview.html

You can also use this JQuery plugin http://www.openxrest.com/translatejs 您也可以使用此JQuery插件 http://www.openxrest.com/translatejs

You can use bing translate .. http://setahost.com/bing-translate-api-with-jquery-ajax/ Bing api is still free 您可以使用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