提问者:小点点

如何将用户在HTML文本框中键入的内容打印到屏幕上?


我正在寻找打印出什么用户键入

<div style="text-align:center;">
   <h3>- Students Name & Age -</h3>
   <input id="d1">
   <button class="button" onclick="addName()">Submit</button>
</div>

共3个答案

匿名用户

null

function addName() {
  var div = document.createElement("div");
  div.innerHTML = document.getElementById('d1').value;
  document.getElementById("name").appendChild(div);
}
<div style="text-align:center;">
  <h3>- Students Name & Age -</h3>
  <input id="d1">
  <button class="button" onclick="addName()">Submit</button>
</div>
<div id="name"></div>

匿名用户

您可以使用onkeyup更新您按下的每个键的值

null

print = document.getElementById('print');

function printfun(){
    print.innerHTML = document.getElementById('d1').value;
}
<div id="print"></div>

<div style="text-align:center;">
   <h3>- Students Name & Age -</h3>
   <input type="number" id="d1" onkeyup="printfun()">
   <button class="button" id="SubmitStudentInformation" onclick="addName()">Submit</button>
</div>

匿名用户

使用JavaScript:

null

var addName = function() {
   alert(document.getElementById('d1').value);
}
<div style="text-align:center;">
   <h3>- Students Name & Age -</h3>
   <input id="d1">
   <button class="button" onclick="addName()">Submit</button>
</div>