2017-03-22 25 views
0

我有2个HTML(表单元素)输入,都是文本类型。当我在第一个文字中写字时,我希望我写的同一文字出现在第二个文字输入中。这可能吗?怎么样?这在网上很难找到。同时编辑多个HTML文本输入

+0

你需要使用JavaScript钩到第一'input'输入事件,并设置成第二值。 –

+0

将更改事件处理程序添加到第一个输入。在这次更新中,第二个。 – Richard

回答

4

document.getElementById('first').onkeyup = function(e) { 
 
    document.getElementById('second').value = e.target.value; 
 
}
<input type="text" id="first" placeholder="Type in this"> 
 
<input type="text" id="second">

+1

这工作,谢谢!我正在使用Angular 2,所以我在他们的文档中找到了更好/更简单的解决方案,但我要求提供一般HTML,因此您的答案更合适,并且可以帮助其他人更多:) – MariusJ

1
<input type="text" id="inputFirst" onchange="mutipleText()"> 
<input type="text" id="inputSecond" > 

function mutipleText(){ 
    var firstInput = $('#inputFirst').val(); 
    $('#inputSecond').val(firstInput) 
    }