2017-06-12 60 views
-1

我需要传递并设置输入id =“a”的值以在输入id时输入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 
+0

你尝试过什么?什么是'$ a'?您似乎想要使用keyup事件,那么您是否编写了任何代码来尝试它? – j08691

+0

是的我尝试使用keyup事件的下一个方法:IDa.addEventListener('keyup') – cfranco

+0

基本上,我需要知道如何将一个变量的值分配给Id元素,例如:document.getElementById('b') 。 Value =变量'a'当a.addEventListener('keyup') – cfranco

回答

-1

你可以试试这个..

<!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> 
+0

不知道人们为什么标记-ve无缘无故:/ –