我正在尝试在单独的div上显示用户输入,但是只有在单击按钮时才显示它。我想我已经设置好了,但是我不确定如何显示输入。有人可以帮助我完成它吗?



<script>
    var callButt = document.getElementById("callButt");
    var userinput = document.getElementById("userinput");

    callButt.addEventListener("click", function(){
    console.log("Call has been set");

    userinput.style.display = "block";

</script>

<input id="callerIDInput" type="text" value="" >
<div id="userinput"> </div>

<button id='callButt'>CALL</button>

最佳答案

input value设置为div的innerHTML



var callButt = document.getElementById("callButt");
var userinput = document.getElementById("userinput");
callButt.addEventListener("click", function() {
      console.log("Call has been set");
      userinput.innerHTML = document.getElementById('callerIDInput').value
      })

<input id="callerIDInput" type="text" value="">
<div id="userinput"> </div>

<button id='callButt'>CALL</button>

08-18 23:06