简体   繁体   English

在输入框中显示实时结果

[英]Display real time results in input box

I am trying to display the results of an input in real time in another disabled input box and am not having much luck. 我试图在另一个禁用的输入框中实时显示输入结果,但运气不佳。 Code below: 代码如下:

var inputBox = document.getElementById('input');

inputBox.onkeyup = function(){
    document.getElementById('output').innerHTML = inputBox.value*2;
}

<input type='text' id='input'>

<input type='text' id='output' disabled>

Can anyone help? 有人可以帮忙吗?

Thanks, 谢谢,

John 约翰

Try adding a listener and use value instead of innerHTML: 尝试添加一个侦听器并使用value代替innerHTML:

document.getElementById('input').addEventListener("keyup", myFunction);

var inputBox = document.getElementById('input');

function myFunction(){
    document.getElementById('output').value = inputBox.value*2;
}

JSfiddle: https://jsfiddle.net/22t37834/ JSfiddle: https ://jsfiddle.net/22t37834/

Use the 'keyup' as it is fired after the char is entered. 输入字符后会触发“ keyup”。

$("#input").keyup (function (e) {
     $('#output').val($(this).val() * 2);
});

Try This one - 试试这个-

 var inputBox = document.getElementById('input'); inputBox.onkeyup = function(){ document.getElementById('output').innerHTML = inputBox.value*2; var val = document.getElementById('input').value document.getElementById('output').value = val; } 
 <input type='text' id='input'> <input type='text' id='output' disabled> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM