Javascript 如何获取输入值并在其他输入中设置此值

Javascript 如何获取输入值并在其他输入中设置此值,javascript,Javascript,我需要通过并在键控时将输入id=“a”的值设置为输入id=“b”。有什么想法吗 <input id="a" name="a" value="" type="text"> <input id="b" name="b" value="" type="text"> var a = document.getElemntById('a').value var b = document.getElementById('b').value = $a var a=document.

我需要通过并在键控时将输入id=“a”的值设置为输入id=“b”。有什么想法吗

<input id="a" name="a" value="" type="text">
<input id="b" name="b" value="" type="text">

var a = document.getElemntById('a').value
var b = document.getElementById('b').value = $a

var a=document.getElemntById('a')。值
var b=document.getElementById('b')。值=$a
你可以试试这个

 <!DOCTYPE html>
 <html>
 <body>

   Name: <input type="text" id="myText" >
   2nd Name : <input type="text" id="myText2" >
   <p>Click the button to change the value of the text field.</p>
    <button onclick="myFunction()">Try it</button>
      <script>
function myFunction() {
  document.getElementById("myText2").value = document.getElementById("myText").value;
   }
     </script>

 </body>
 </html>

姓名:
第二名:
单击按钮更改文本字段的值

试试看 函数myFunction(){ document.getElementById(“myText2”).value=document.getElementById(“myText”).value; }
您尝试过什么?什么是
$a
?您似乎想要使用keyup事件,那么您是否编写了任何代码来尝试它?是的,我尝试以下一种方式使用keyup事件:IDa.addEventListener('keyup')。基本上,我需要知道如何将变量的值分配给Id元素,例如:document.getElementById('b')。值=a.addEventListener('keyup')时的变量“a”